summaryrefslogtreecommitdiffstats
path: root/buildtools/pascal/pascalglobaloptionsdlg.cpp
blob: a88e901caccbe4d39b521a56f6099ce85f5bde48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *   Copyright (C) 2003 Alexander Dymo                                     *
 *   cloudtemple@mksat.net                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqcombobox.h>

#include <kurlrequester.h>
#include <kdebug.h>
#include <kconfig.h>

#include "kdevcompileroptions.h"

#include "service.h"
#include "pascalproject_part.h"
#include "pascalglobaloptionsdlg.h"

PascalGlobalOptionsDlg::PascalGlobalOptionsDlg(PascalProjectPart *part, TQWidget* parent, const char* name, WFlags fl)
    :PascalProjectOptionsDlgBase(parent,name,fl), m_part(part)
{
    delete config_label;
    delete config_combo;
    delete addconfig_button;
    delete removeconfig_button;
    delete compiler_label;
    delete configuration_layout;
    delete configuration_line;
    delete exec_label;
    delete exec_edit;
    delete mainSourceLabel;
    delete mainSourceUrl;
    delete defaultopts_button;


    offers = KTrader::self()->query("KDevelop/CompilerOptions", "[X-KDevelop-Language] == 'Pascal'");

    ServiceComboBox::insertStringList(compiler_box, offers, &service_names, &service_execs);

    if (offers.isEmpty())
        options_button->setEnabled(false);

    currentCompiler = TQString();

    /*kdDebug() << ServiceComboBox::defaultCompiler() << endl;
    kdDebug() << ServiceComboBox::itemForText(ServiceComboBox::defaultCompiler(), service_names) << endl;
    kdDebug() << compiler_box->text(ServiceComboBox::itemForText(ServiceComboBox::defaultCompiler(), service_names)) << endl;
*/
    ServiceComboBox::setCurrentText(compiler_box, ServiceComboBox::defaultCompiler(), service_names);
    compiler_box_activated(compiler_box->currentText());
}

PascalGlobalOptionsDlg::~PascalGlobalOptionsDlg()
{
}

void PascalGlobalOptionsDlg::optionsButtonClicked()
{
    TQString name = ServiceComboBox::currentText(compiler_box, service_names);
    KDevCompilerOptions *plugin = m_part->createCompilerOptions(name);

    if (plugin) {
        TQString flags = plugin->exec(this, options_edit->text());
        options_edit->setText(flags);
        delete plugin;
    }
}

void PascalGlobalOptionsDlg::compiler_box_activated(const TQString& text)
{
    kdDebug() << "text changed from " << currentCompiler << " to " << text << endl;
    if (currentCompiler == text)
        return;
    if (!currentCompiler.isEmpty())
        saveCompilerOpts(currentCompiler);
    currentCompiler = text;
    readCompilerOpts(currentCompiler);
}

void PascalGlobalOptionsDlg::accept()
{
    saveCompilerOpts(currentCompiler);

    saveConfigCache();
}

void PascalGlobalOptionsDlg::saveCompilerOpts( TQString compiler )
{
    configCache[compiler] = options_edit->text();
}

void PascalGlobalOptionsDlg::readCompilerOpts( TQString compiler )
{
    TQString settings = configCache[compiler];
    if (settings.isEmpty())
    {
        KConfig *config = KGlobal::config();
        config->setGroup("Pascal Compiler");
        settings = config->readPathEntry(compiler);
    }

    options_edit->setText(settings);
}

void PascalGlobalOptionsDlg::readConfigCache( )
{
/*    KConfig *config = KGlobal::config();
    config->setGroup("Pascal Compiler");

    TQMap<TQString, TQString> settings = config->entryMap("Pascal Compiler");
*/
}

void PascalGlobalOptionsDlg::saveConfigCache( )
{
    KConfig *config = KGlobal::config();
    config->setGroup("Pascal Compiler");

    for (TQMap<TQString, TQString>::iterator it = configCache.begin(); it != configCache.end(); ++it)
    {
        config->writeEntry(it.key(), it.data());
    }
}

#include "pascalglobaloptionsdlg.moc"