summaryrefslogtreecommitdiffstats
path: root/config/exportthemedialog.cpp
blob: ccb9cce061b3c4a582a5d6786aad1d218e8ee5e3 (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
/*
  QtCurve (C) Craig Drummond, 2003 - 2010 craig.p.drummond@gmail.com

  ----

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public
  License version 2 as published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  Boston, MA 02110-1301, USA.
*/

#include "exportthemedialog.h"
#include <tdelocale.h>
#include <kurlrequester.h>
#include <klineedit.h>
#include <tdemessagebox.h>
#include <tdeconfig.h>
#include <tqdir.h>
#include <tqlabel.h>
#include <tqlayout.h>
#define CONFIG_WRITE
#include "config_file.c"

CExportThemeDialog::CExportThemeDialog(TQWidget *parent)
                  : KDialogBase(parent, "ExportDialog", true, i18n("Export Theme"),
                                Ok|Cancel)
{
    TQWidget     *page = new TQWidget(this);
    TQGridLayout *layout = new TQGridLayout(page, 3, 2, 0, spacingHint());

    layout->addWidget(new TQLabel(i18n("Name:"), page), 0, 0);
    layout->addWidget(new TQLabel(i18n("Comment:"), page), 1, 0);
    layout->addWidget(new TQLabel(i18n("Destination folder:"), page), 2, 0);
    layout->addWidget(themeName=new TQLineEdit(page), 0, 1);
    layout->addWidget(themeComment=new TQLineEdit(i18n("QtCurve based theme"), page), 1, 1);
    layout->addWidget(themeUrl=new KURLRequester(page), 2, 1);

    themeUrl->setMode(KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly);
    themeUrl->lineEdit()->setReadOnly(true);
    themeUrl->setURL(TQDir::homeDirPath());
    setMainWidget(page);
}

void CExportThemeDialog::run(const Options &o)
{
    opts=o;
    exec();
}

void CExportThemeDialog::slotOk()
{
    TQString name(themeName->text().stripWhiteSpace().lower());

    if(name.isEmpty())
        KMessageBox::error(this, i18n("Name is empty!"));
    else
    {
        TQString fileName(themeUrl->url()+"/"+THEME_PREFIX+name+".themerc");

        TDEConfig cfg(fileName, false, false);
        bool    rv(!cfg.isReadOnly());

        if(rv)
        {
            cfg.setGroup("Misc");
            cfg.writeEntry("Name", themeName->text().stripWhiteSpace());
            cfg.writeEntry("Comment", themeComment->text());
            cfg.setGroup("KDE");
            cfg.writeEntry("WidgetStyle", THEME_PREFIX+name);

            rv=writeConfig(&cfg, opts, opts, true);
        }

        if(rv)
        {
            TQDialog::accept();
            KMessageBox::information(this, i18n("Succesfully created:\n%1").arg(fileName));
        }
        else
            KMessageBox::error(this, i18n("Failed to create file: %1").arg(fileName));
    }
}

#include "exportthemedialog.moc"