summaryrefslogtreecommitdiffstats
path: root/configdialog/main.cpp
blob: 09de4524c5544bba39cfd0b936e5b2de38d16bdc (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 *   Copyright (C) 2006
 *   Siraj Razick <[email protected]>
 *   PhobosK <[email protected]>
 *   see Also AUTHORS
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library 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 Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <config.h>

#include <unistd.h>

#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kdebug.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kuniqueapplication.h>

#include "kbfxconfigapp.h"

static const char description[] = I18N_NOOP ( "KBFX Configuration Utility" );
static const char version[] = APPLICATION_VERSION;
static const KCmdLineOptions options[] =
    {
        {"install <theme URL>", I18N_NOOP ( "Install KBFX theme from <URL>" ), 0},
        { "prepare <folder URL>", I18N_NOOP ( "Prepare KBFX theme from folder <URL>" ), 0 },
        { "about", I18N_NOOP ( "Show the About page" ), 0 },
        KCmdLineLastOption
    };

static KbfxConfigApp *mainWin = 0;

class KbfxConfigApplication : public KUniqueApplication
{
	public:
	   KbfxConfigApplication() { }
	   virtual ~KbfxConfigApplication() { }

	   virtual int newInstance()
		{
			KCmdLineArgs* KbfxArgs = KCmdLineArgs::parsedArgs();

			/* prepare kbfx theme cmdline option given */
			if ( KbfxArgs->isSet ( "prepare" ) )
			{
				TQString m_KbfxThemeFolderUrl = KbfxArgs->getOption ( "prepare" );
				if ( m_KbfxThemeFolderUrl.endsWith ( "/" ) ) m_KbfxThemeFolderUrl.truncate ( m_KbfxThemeFolderUrl.length()-1 );
				TQString theme_name = m_KbfxThemeFolderUrl.section ( '/', -1 );
				TQString archive_dir = m_KbfxThemeFolderUrl.section ( '/', 0, -2 );
				TQString archive_name = archive_dir+"/"+ theme_name+".kbfxtheme";
				kdDebug() << "Prepare option arguments: "
				<< theme_name
				<< endl
				<< archive_dir
				<< endl
				<< archive_name
				<< endl;

				KTar ThemeArchive ( archive_name,"application/x-bzip" );

				if ( !ThemeArchive.open ( IO_WriteOnly ) )
				{
					KMessageBox::sorry ( 0,
										tr2i18n ( "<p align='center'>Could not create this KBFX theme package.</p>" ) );

					kdDebug() << "Error creating theme file: "
					<< archive_name
					<< endl;
				}
				else
				{
					ThemeArchive.addLocalDirectory ( m_KbfxThemeFolderUrl,theme_name );
					ThemeArchive.close ();
					KMessageBox::information ( 0,
											tr2i18n ( "<p align='center'>KBFX Theme <strong>%1</strong> prepared.</p>" ).arg ( theme_name ),
											tr2i18n ( "KBFX Theme Ready" ) );
					kdDebug() << "KBFX theme file ready: "
					<< archive_name
					<< endl;
				}

				kdDebug() << "KBFX theme prepared. Quitting..." << endl;
				TQTimer::singleShot ( 100, mainWin, TQT_SLOT ( deleteLater() ) );
			}
			else
			{
				/* install kbfx theme cmdline option given */
				if ( KbfxArgs->isSet ( "install" ) )
				{
					TQString m_KbfxThemeUrl = KbfxArgs->getOption ( "install" );
					kdDebug() << "Install option argument: "
					<< m_KbfxThemeUrl
					<< endl;

					mainWin->lb_Main->setCurrentItem ( THEMES );
					mainWin->KbfxMenuItemChanged ( THEMES );
					mainWin->KbfxThemeInstall ( m_KbfxThemeUrl );
				}

				/* show the "About" page */
				if ( KbfxArgs->isSet ( "about" ) )
				{
					kdDebug() << "About option argument given on command line."
					<< endl;

					mainWin->lb_Main->setCurrentItem ( ABOUT );
					mainWin->KbfxMenuItemChanged ( ABOUT );
				}

				mainWin->show();
				mainWin->browserInit();
			}
			return KUniqueApplication::newInstance();
		}
};

int main ( int argc, char **argv )
{
	KAboutData about ( "kbfxconfigapp",
	                   I18N_NOOP ( "kbfxconfigapp" ),
	                   version,
	                   description,
	                   KAboutData::License_GPL,
	                   "(C) 2006 PhobosK",
	                   0,
	                   0,
	                   "[email protected]" );
	about.addAuthor ( "PhobosK", 0, "[email protected]" );

    KCmdLineArgs::init( argc, argv, &about );
    KUniqueApplication::addCmdLineOptions();
    KCmdLineArgs::addCmdLineOptions( options );

    if (!KUniqueApplication::start())
	return 1;

    KbfxConfigApplication app;

	mainWin = new KbfxConfigApp();
/*
	Don't show initially untill found out if prepare option is given on the command line
    mainWin->show();
*/
 	app.setMainWidget ( mainWin );

	/* mainWin has WDestructiveClose flag by default, so it will delete itself */
    return  app.exec();
}