summaryrefslogtreecommitdiff
path: root/core/settings/launcher/tabssettings.cpp
blob: 17a1609f4680ac4274a3bd2954b993bc0d386ad1 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/*
               =.            This file is part of the OPIE Project
             .=l.            Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
           .>+-=
 _;:,     .>    :=|.         This file is free software; you can
.> <`_,   >  .   <=          redistribute it and/or modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This file 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 file;
  -_. . .   )=.  =           see the file COPYING. If not, write to the
    --        :-=`           Free Software Foundation, Inc.,
                             59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#include "tabssettings.h"

#include <qpe/resource.h>
#include <qpe/applnk.h>
#include <qpe/mimetype.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>

#include <qlistbox.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qwhatsthis.h>
#include <qcheckbox.h>

#include "tabdialog.h"

#include <stdlib.h>
#include <qmessagebox.h>


#define GLOBALID 	".global."


TabsSettings::TabsSettings ( QWidget *parent, const char *name )
	: QWidget ( parent, name )
{
	QGridLayout *lay = new QGridLayout ( this, 0, 0, 4, 4 );

	QLabel *l = new QLabel ( tr( "Launcher Tabs:" ), this );
	lay-> addMultiCellWidget ( l, 0, 0, 0, 1 );

	m_list = new QListBox ( this );
	lay-> addMultiCellWidget ( m_list, 1, 4, 0, 0 );

	QWhatsThis::add ( m_list, tr( "foobar" ));

	QPushButton *p1, *p2, *p3;
	p1 = new QPushButton ( tr( "New" ), this );
	lay-> addWidget ( p1, 1, 1 );
	connect ( p1, SIGNAL( clicked ( )), this, SLOT( newClicked ( )));

	p2 = new QPushButton ( tr( "Edit" ), this );
	lay-> addWidget ( p2, 2, 1 );
	connect ( p2, SIGNAL( clicked ( )), this, SLOT( editClicked ( )));

	p3 = new QPushButton ( tr( "Delete" ), this );
	lay-> addWidget ( p3, 3, 1 );
	connect ( p3, SIGNAL( clicked ( )), this, SLOT( deleteClicked ( )));

	lay-> setRowStretch ( 4, 10 );

                m_bigbusy = new QCheckBox( tr( "Enable big busy indicator" ),  this );
                lay-> addMultiCellWidget ( m_bigbusy, 5, 5, 0, 1 );

	m_busyani = new QCheckBox ( tr( "Enable animated busy indicator" ), this );
	lay-> addMultiCellWidget ( m_busyani, 6, 6, 0, 1 );

	p1-> setEnabled ( false );
	p3-> setEnabled ( false );

	init ( );

	QWhatsThis::add ( m_list, tr( "Select the Launcher Tab you want to edit or delete." ));
	QWhatsThis::add ( p1, tr( "Adds a new Tab to the Launcher." ) + QString ( "<center><br><i>not yet implemented</i><br>Please use the tabmanager</center>." ));
	QWhatsThis::add ( p2, tr( "Opens a new dialog to customize the select Tab." ));
	QWhatsThis::add ( p3, tr( "Deletes a Tab from the Launcher." ) + QString ( "<center><br><i>not yet implemented</i><br>Please use the tabmanager</center>." ));
        	QWhatsThis::add ( m_bigbusy, tr( "Activate this, if you want a big busy indicator in the middle of the screen instead of the one in taskbar." ));
	QWhatsThis::add ( m_busyani, tr( "Activate this, if you want an animatedbusy indicator for starting applications in the Launcher." ));
}

void TabsSettings::init ( )
{
	AppLnkSet rootFolder( MimeType::appsFolderName ( ));
	QStringList types = rootFolder. types ( );

	m_list-> insertItem ( tr( "All Tabs" ));
	m_ids << GLOBALID;

	for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
		m_list-> insertItem ( rootFolder. typePixmap ( *it ), rootFolder. typeName ( *it ));
		m_ids << *it;
	}
	QImage img ( Resource::loadImage ( "DocsIcon" ));
	QPixmap pix;
	pix = img. smoothScale ( AppLnk::smallIconSize ( ), AppLnk::smallIconSize ( ));
	m_list-> insertItem ( pix, tr( "Documents" ));
	m_ids += "Documents"; // No tr

	Config cfg ( "Launcher" );

	readTabSettings ( cfg );

	cfg. setGroup ( "GUI" );
	m_busyani-> setChecked ( cfg. readEntry ( "BusyType" ). lower ( ) == "animated" );
                m_bigbusy->setChecked(  cfg. readBoolEntry ( "BigBusy" )  );
}


void TabsSettings::readTabSettings ( Config &cfg )
{
	QString grp ( "Tab %1" ); // No tr
	m_tabs. clear ( );

	TabConfig global_def;
	global_def. m_view        = TabConfig::Icon;
	global_def. m_bg_type     = TabConfig::Ruled;
	global_def. m_bg_image    = "launcher/opie-background";
	global_def. m_bg_color    = colorGroup ( ). color ( QColorGroup::Base ). name ( );
	global_def. m_text_color  = colorGroup ( ). color ( QColorGroup::Text ). name ( );
	global_def. m_font_use    = false;
	global_def. m_font_family = font ( ). family ( );
	global_def. m_font_size   = font ( ). pointSize ( );
	global_def. m_font_weight = 50;
	global_def. m_font_italic = false;
	global_def. m_changed     = false;


	for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
		TabConfig tc = ( it != m_ids. begin ( )) ? m_tabs [GLOBALID] : global_def;

		cfg. setGroup ( grp. arg ( *it ));

		QString view = cfg. readEntry ( "View" );
		if ( view == "Icon" ) // No tr
			tc. m_view = TabConfig::Icon;
		if ( view == "List" ) // No tr
			tc. m_view = TabConfig::List;

		QString bgType = cfg. readEntry ( "BackgroundType" );
		if ( bgType == "Image" )
			tc. m_bg_type = TabConfig::Image;
		else if ( bgType == "SolidColor" )
			tc. m_bg_type = TabConfig::SolidColor;
		else if ( bgType == "Image" ) // No tr
			tc. m_bg_type = TabConfig::Image;

		tc. m_bg_image = cfg. readEntry ( "BackgroundImage", tc. m_bg_image );
		tc. m_bg_color = cfg. readEntry ( "BackgroundColor", tc. m_bg_color );
		tc. m_text_color = cfg. readEntry ( "TextColor", tc. m_text_color );
		QStringList f = cfg. readListEntry ( "Font", ',' );
		if ( f. count ( ) == 4 ) {
			tc. m_font_use = true;
			tc. m_font_family = f [0];
			tc. m_font_size = f [1]. toInt ( );
			tc. m_font_weight = f [2]. toInt ( );
			tc. m_font_italic = ( f [3]. toInt ( ));
		}
		m_tabs [*it] = tc;
	}

	// if all tabs have the same config, then initialize the GLOBALID tab to these values

	TabConfig *first = 0;
	bool same = true;

	for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
		if ( *it == GLOBALID )
			continue;
		else if ( !first )
			first = &m_tabs [*it];
		else
			same &= ( *first == m_tabs [*it] );
	}
	if ( same ) {
		m_tabs [GLOBALID] = *first;
		m_tabs [GLOBALID]. m_changed = true;
	}
}


void TabsSettings::accept ( )
{
	Config cfg ( "Launcher" );

	// Launcher Tab
	QString grp ( "Tab %1" ); // No tr

	for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
		TabConfig &tc = m_tabs [*it];

		if ( !tc. m_changed )
			continue;

		cfg. setGroup ( grp. arg ( *it ));
		switch ( tc. m_view ) {
			case TabConfig::Icon:
				cfg.writeEntry ( "View", "Icon" );
				break;
			case TabConfig::List:
				cfg.writeEntry ( "View", "List" );
				break;
		}

		QCopEnvelope e ( "QPE/Launcher", "setTabView(QString,int)" );
		e << *it << tc. m_view;

		cfg. writeEntry ( "BackgroundImage", tc. m_bg_image );
		cfg. writeEntry ( "BackgroundColor", tc. m_bg_color );
		cfg. writeEntry ( "TextColor", tc. m_text_color );

		if ( tc. m_font_use ) {
			QString f = tc. m_font_family + "," + QString::number ( tc. m_font_size ) + "," + QString::number ( tc. m_font_weight ) + "," + ( tc. m_font_italic ? "1" : "0" );
			cfg. writeEntry ( "Font", f );
		}
		else
			cfg. removeEntry ( "Font" );

		QCopEnvelope be ( "QPE/Launcher", "setTabBackground(QString,int,QString)" );

		switch ( tc. m_bg_type ) {
			case TabConfig::Ruled:
				cfg.writeEntry( "BackgroundType", "Ruled" );
				be << *it << tc. m_bg_type << QString("");
				break;
			case TabConfig::SolidColor:
				cfg.writeEntry( "BackgroundType", "SolidColor" );
				be << *it << tc. m_bg_type << tc. m_bg_color;
				break;
			case TabConfig::Image:
				cfg.writeEntry( "BackgroundType", "Image" );
				be << *it << tc. m_bg_type << tc. m_bg_image;
				break;
		}

		QCopEnvelope te( "QPE/Launcher", "setTextColor(QString,QString)" );
		te << *it << tc. m_text_color;

		QCopEnvelope fe ( "QPE/Launcher", "setFont(QString,QString,int,int,int)" );
		fe << *it;
		fe << ( tc. m_font_use ? tc. m_font_family : QString::null );
		fe << tc. m_font_size;
		fe << tc. m_font_weight;
		fe << ( tc. m_font_italic ? 1 : 0 );

		tc. m_changed = false;
	}
	cfg. setGroup ( "GUI" );
	QString busytype = QString ( m_busyani-> isChecked ( ) ? "Animated" : "" );
	cfg. writeEntry ( "BusyType", busytype );

        	cfg. writeEntry ( "BigBusy", m_bigbusy->isChecked( ) );

	{
		QCopEnvelope e ( "QPE/Launcher", "setBusyIndicatorType(QString)" );
		e << busytype;
	}
}

void TabsSettings::newClicked ( )
{
	QMessageBox::information ( this, tr( "Error" ), tr( "Not implemented yet" ));
}

void TabsSettings::deleteClicked ( )
{
	int ind = m_list-> currentItem ( );

	if ( ind < 0 )
		return;

	QMessageBox::information ( this, tr( "Error" ), tr( "Not implemented yet" ));
}

void TabsSettings::editClicked ( )
{
	int ind = m_list-> currentItem ( );

	if ( ind < 0 )
		return;

	TabConfig tc = m_tabs [m_ids [ind]];

	TabDialog *d = new TabDialog ( m_list-> pixmap ( ind ), m_list-> text ( ind ), tc, this, "TabDialog", true );

	if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) {
		tc. m_changed = true;
		m_tabs [m_ids [ind]] = tc;

		if ( m_ids [ind] == GLOBALID ) {
			for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
				if ( *it != GLOBALID )
					m_tabs [*it] = tc;
			}
		}
	}

	delete d;
}