00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "tabssettings.h"
00029
00030 #include <opie2/oresource.h>
00031
00032 #include <qpe/applnk.h>
00033 #include <qpe/mimetype.h>
00034 #include <qpe/qcopenvelope_qws.h>
00035 #include <qpe/config.h>
00036 #include <qpe/qpeapplication.h>
00037
00038 #include <qlistbox.h>
00039 #include <qpushbutton.h>
00040 #include <qlayout.h>
00041 #include <qlabel.h>
00042 #include <qwhatsthis.h>
00043 #include <qcheckbox.h>
00044
00045 #include "tabdialog.h"
00046
00047 #include <stdlib.h>
00048 #include <qmessagebox.h>
00049
00050
00051 #define GLOBALID ".global."
00052
00053
00054 TabsSettings::TabsSettings ( QWidget *parent, const char *name )
00055 : QWidget ( parent, name )
00056 {
00057 QGridLayout *lay = new QGridLayout ( this, 0, 0, 4, 4 );
00058
00059 QLabel *l = new QLabel ( tr( "Launcher Tabs:" ), this );
00060 lay-> addMultiCellWidget ( l, 0, 0, 0, 1 );
00061
00062 m_list = new QListBox ( this );
00063 lay-> addMultiCellWidget ( m_list, 1, 4, 0, 0 );
00064
00065 QWhatsThis::add ( m_list, tr( "foobar" ));
00066
00067 QPushButton *p1, *p2, *p3;
00068 p1 = new QPushButton ( tr( "New" ), this );
00069 lay-> addWidget ( p1, 1, 1 );
00070 connect ( p1, SIGNAL( clicked()), this, SLOT( newClicked()));
00071
00072 p2 = new QPushButton ( tr( "Edit" ), this );
00073 lay-> addWidget ( p2, 2, 1 );
00074 connect ( p2, SIGNAL( clicked()), this, SLOT( editClicked()));
00075
00076 p3 = new QPushButton ( tr( "Delete" ), this );
00077 lay-> addWidget ( p3, 3, 1 );
00078 connect ( p3, SIGNAL( clicked()), this, SLOT( deleteClicked()));
00079
00080 lay-> setRowStretch ( 4, 10 );
00081
00082 m_bigbusy = new QCheckBox( tr( "Enable big busy indicator" ), this );
00083 lay-> addMultiCellWidget ( m_bigbusy, 5, 5, 0, 1 );
00084
00085 m_busyani = new QCheckBox ( tr( "Enable animated busy indicator" ), this );
00086 lay-> addMultiCellWidget ( m_busyani, 6, 6, 0, 1 );
00087
00088 m_staticbackground = new QCheckBox( tr( "Enable static background pixmap" ), this );
00089 lay->addMultiCellWidget( m_staticbackground, 7, 7, 0, 1 );
00090
00091 p1-> setEnabled ( false );
00092 p3-> setEnabled ( false );
00093
00094 init ( );
00095
00096 QWhatsThis::add ( m_list, tr( "Select the Launcher Tab you want to edit or delete." ));
00097 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>." ));
00098 QWhatsThis::add ( p2, tr( "Opens a new dialog to customize the select Tab." ));
00099 QWhatsThis::add ( p3, tr( "Deletes a Tab from the Launcher." ) + QString ( "<center><br><i>not yet implemented</i><br>Please use the tabmanager</center>." ));
00100 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." ));
00101 QWhatsThis::add ( m_busyani, tr( "Activate this, if you want an animatedbusy indicator for starting applications in the Launcher." ));
00102 QWhatsThis::add ( m_staticbackground, tr( "Activate this, if you want the background pixmap not to scroll with the icons." ));
00103 }
00104
00105 void TabsSettings::init ( )
00106 {
00107 AppLnkSet rootFolder( MimeType::appsFolderName ( ));
00108 QStringList types = rootFolder. types ( );
00109
00110 m_list-> insertItem ( tr( "All Tabs" ));
00111 m_ids << GLOBALID;
00112
00113 for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
00114 m_list-> insertItem ( rootFolder. typePixmap ( *it ), rootFolder. typeName ( *it ));
00115 m_ids << *it;
00116 }
00117 m_list-> insertItem ( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ), tr( "Documents" ) );
00118 m_ids += "Documents";
00119
00120 Config cfg ( "Launcher" );
00121
00122 readTabSettings ( cfg );
00123
00124 cfg. setGroup ( "GUI" );
00125 m_busyani-> setChecked ( cfg. readEntry ( "BusyType" ). lower ( ) == "animated" );
00126 m_bigbusy->setChecked( cfg. readBoolEntry ( "BigBusy" ) );
00127 m_staticbackground->setChecked( cfg.readBoolEntry( "StaticBackground", true ) );
00128 }
00129
00130
00131 void TabsSettings::readTabSettings ( Config &cfg )
00132 {
00133 QString grp ( "Tab %1" );
00134 m_tabs. clear ( );
00135
00136 TabConfig global_def;
00137 global_def. m_view = TabConfig::Icon;
00138 global_def. m_bg_type = TabConfig::Ruled;
00139 global_def. m_bg_image = "launcher/opie-background";
00140 global_def. m_bg_color = colorGroup ( ). color ( QColorGroup::Base ). name ( );
00141 global_def. m_iconcolumns = 0;
00142 global_def. m_text_color = colorGroup ( ). color ( QColorGroup::Text ). name ( );
00143 global_def. m_font_use = false;
00144 global_def. m_font_family = font ( ). family ( );
00145 global_def. m_font_size = font ( ). pointSize ( );
00146 global_def. m_font_weight = 50;
00147 global_def. m_font_italic = false;
00148 global_def. m_changed = false;
00149
00150 Config cfg2 = Config( "Launchersettings" );
00151
00152 for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
00153 TabConfig tc = ( it != m_ids. begin ( )) ? m_tabs [GLOBALID] : global_def;
00154
00155 cfg. setGroup ( grp. arg ( *it ));
00156 cfg2. setGroup( grp. arg ( *it ));
00157
00158 QString view = cfg. readEntry ( "View" );
00159 if ( view == "Icon" )
00160 tc. m_view = TabConfig::Icon;
00161 if ( view == "List" )
00162 tc. m_view = TabConfig::List;
00163
00164 QString bgType = cfg. readEntry ( "BackgroundType" );
00165 if ( bgType == "Image" )
00166 tc. m_bg_type = TabConfig::Image;
00167 else if ( bgType == "SolidColor" )
00168 tc. m_bg_type = TabConfig::SolidColor;
00169 else if ( bgType == "Image" )
00170 tc. m_bg_type = TabConfig::Image;
00171
00172 tc. m_bg_image = cfg. readEntry ( "BackgroundImage", tc. m_bg_image );
00173 tc. m_last_directory = cfg2.readEntry( "DefaultDir", "" );
00174 tc. m_bg_color = cfg. readEntry ( "BackgroundColor", tc. m_bg_color );
00175 tc. m_iconcolumns = cfg. readNumEntry ( "Columns", tc. m_iconcolumns );
00176 qDebug( "m_iconcolumns for %s = %d", (const char*) *it, tc.m_iconcolumns );
00177 tc. m_text_color = cfg. readEntry ( "TextColor", tc. m_text_color );
00178 QStringList f = cfg. readListEntry ( "Font", ',' );
00179 if ( f. count ( ) == 4 ) {
00180 tc. m_font_use = true;
00181 tc. m_font_family = f [0];
00182 tc. m_font_size = f [1]. toInt ( );
00183 tc. m_font_weight = f [2]. toInt ( );
00184 tc. m_font_italic = ( f [3]. toInt ( ));
00185 }
00186 m_tabs [*it] = tc;
00187 }
00188
00189
00190
00191 TabConfig *first = 0;
00192 bool same = true;
00193
00194 for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
00195 if ( *it == GLOBALID )
00196 continue;
00197 else if ( !first )
00198 first = &m_tabs [*it];
00199 else
00200 same &= ( *first == m_tabs [*it] );
00201 }
00202 if ( same ) {
00203 m_tabs [GLOBALID] = *first;
00204 m_tabs [GLOBALID]. m_changed = true;
00205 }
00206 }
00207
00208
00209 void TabsSettings::accept ( )
00210 {
00211 Config cfg ( "Launcher" );
00212 Config cfg2 ( "Launchersettings" );
00213
00214
00215 QString grp ( "Tab %1" );
00216
00217 for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
00218 TabConfig &tc = m_tabs [*it];
00219
00220 if ( !tc. m_changed )
00221 continue;
00222
00223 cfg. setGroup ( grp. arg ( *it ));
00224 cfg2. setGroup ( grp. arg ( *it ));
00225 switch ( tc. m_view ) {
00226 case TabConfig::Icon:
00227 cfg.writeEntry ( "View", "Icon" );
00228 break;
00229 case TabConfig::List:
00230 cfg.writeEntry ( "View", "List" );
00231 break;
00232 }
00233
00234 QCopEnvelope e ( "QPE/Launcher", "setTabView(QString,int)" );
00235 e << *it << tc. m_view;
00236
00237 cfg. writeEntry ( "BackgroundImage", tc. m_bg_image );
00238 cfg. writeEntry ( "BackgroundColor", tc. m_bg_color );
00239 cfg. writeEntry ( "Columns", tc. m_iconcolumns );
00240 cfg. writeEntry ( "TextColor", tc. m_text_color );
00241 cfg2. writeEntry ( "DefaultDir", tc.m_last_directory );
00242
00243 if ( tc. m_font_use ) {
00244 QString f = tc. m_font_family + "," + QString::number ( tc. m_font_size ) + "," + QString::number ( tc. m_font_weight ) + "," + ( tc. m_font_italic ? "1" : "0" );
00245 cfg. writeEntry ( "Font", f );
00246 }
00247 else
00248 cfg. removeEntry ( "Font" );
00249
00250 QCopEnvelope be ( "QPE/Launcher", "setTabBackground(QString,int,QString)" );
00251
00252 switch ( tc. m_bg_type ) {
00253 case TabConfig::Ruled:
00254 cfg.writeEntry( "BackgroundType", "Ruled" );
00255 be << *it << tc. m_bg_type << QString("");
00256 break;
00257 case TabConfig::SolidColor:
00258 cfg.writeEntry( "BackgroundType", "SolidColor" );
00259 be << *it << tc. m_bg_type << tc. m_bg_color;
00260 break;
00261 case TabConfig::Image:
00262 cfg.writeEntry( "BackgroundType", "Image" );
00263 be << *it << tc. m_bg_type << tc. m_bg_image;
00264 break;
00265 }
00266
00267 QCopEnvelope te( "QPE/Launcher", "setTextColor(QString,QString)" );
00268 te << *it << tc. m_text_color;
00269
00270 QCopEnvelope ic( "QPE/Launcher", "setIconColumns(QString,int)" );
00271 ic << *it << tc. m_iconcolumns;
00272
00273 QCopEnvelope fe ( "QPE/Launcher", "setFont(QString,QString,int,int,int)" );
00274 fe << *it;
00275 fe << ( tc. m_font_use ? tc. m_font_family : QString::null );
00276 fe << tc. m_font_size;
00277 fe << tc. m_font_weight;
00278 fe << ( tc. m_font_italic ? 1 : 0 );
00279
00280 tc. m_changed = false;
00281 }
00282 cfg. setGroup ( "GUI" );
00283 QString busytype = QString ( m_busyani-> isChecked ( ) ? "Animated" : "" );
00284 cfg. writeEntry ( "BusyType", busytype );
00285 cfg. writeEntry ( "BigBusy", m_bigbusy->isChecked( ) );
00286 cfg. writeEntry ( "StaticBackground", m_staticbackground->isChecked( ) );
00287
00288 {
00289 QCopEnvelope e ( "QPE/Launcher", "setBusyIndicatorType(QString)" );
00290 e << busytype;
00291 }
00292 {
00293 QCopEnvelope e ( "QPE/Launcher", "setStaticBackground(bool)" );
00294 e << m_staticbackground->isChecked();
00295 }
00296 }
00297
00298 void TabsSettings::newClicked ( )
00299 {
00300 QMessageBox::information ( this, tr( "Error" ), tr( "Not implemented yet" ));
00301 }
00302
00303 void TabsSettings::deleteClicked ( )
00304 {
00305 int ind = m_list-> currentItem ( );
00306
00307 if ( ind < 0 )
00308 return;
00309
00310 QMessageBox::information ( this, tr( "Error" ), tr( "Not implemented yet" ));
00311 }
00312
00313 void TabsSettings::editClicked ( )
00314 {
00315 int ind = m_list-> currentItem ( );
00316
00317 if ( ind < 0 )
00318 return;
00319
00320 TabConfig tc = m_tabs [m_ids [ind]];
00321
00322 TabDialog *d = new TabDialog ( m_list-> pixmap ( ind ), m_list-> text ( ind ), tc, this, "TabDialog", true );
00323
00324 if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) {
00325 tc. m_changed = true;
00326 m_tabs [m_ids [ind]] = tc;
00327
00328 if ( m_ids [ind] == GLOBALID ) {
00329 for ( QStringList::Iterator it = m_ids. begin ( ); it != m_ids. end ( ); ++it ) {
00330 if ( *it != GLOBALID )
00331 m_tabs [*it] = tc;
00332 }
00333 }
00334 }
00335
00336 delete d;
00337 }