00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "themeset.h"
00024
00025 #include <qpe/qpeapplication.h>
00026 #include <qpe/global.h>
00027
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 #include <qlistview.h>
00031 #include <qdir.h>
00032
00033 #include <qpe/config.h>
00034
00035
00036 class MyConfig : public Config
00037 {
00038 public:
00039 MyConfig ( const QString &f, Domain d ) : Config ( f, d )
00040 { }
00041
00042 bool hasGroup ( const QString &gname ) const
00043 {
00044 QMap< QString, ConfigGroup>::ConstIterator it = groups. find ( gname );
00045 return ( it != groups.end() );
00046 }
00047 };
00048
00049 class MyItem : public QListViewItem
00050 {
00051 public:
00052 MyItem ( QListView *lv, QListViewItem *after, const QString &name, const QString &comm, const QString &theme ) : QListViewItem ( lv, after, name, comm )
00053 {
00054 m_theme = theme;
00055 }
00056
00057
00058 QString m_theme;
00059 };
00060
00061
00062 ThemeSettings::ThemeSettings ( QWidget* parent, const char *name, WFlags fl )
00063 : QWidget ( parent, name, fl )
00064 {
00065 setCaption ( tr( "Theme Style" ) );
00066
00067 Config config ( "qpe" );
00068 config. setGroup ( "Appearance" );
00069
00070 QString active = config. readEntry ( "Theme", "default" );
00071
00072 QVBoxLayout *vbox = new QVBoxLayout ( this );
00073 vbox-> setSpacing ( 3 );
00074 vbox-> setMargin ( 6 );
00075
00076 vbox-> addWidget ( new QLabel ( tr( "Select the theme to be used" ), this ));
00077
00078 m_list = new QListView ( this );
00079 m_list-> addColumn ( tr( "Name" ));
00080 m_list-> addColumn ( tr( "Description" ));
00081 m_list-> setSelectionMode ( QListView::Single );
00082 m_list-> setAllColumnsShowFocus ( true );
00083 m_list-> setSorting ( -1 );
00084 vbox-> addWidget ( m_list, 10 );
00085
00086 QListViewItem *item = new MyItem ( m_list, 0, tr( "[No theme]" ), "", "" );
00087 m_list-> setSelected ( item, true );
00088
00089 QString path = QPEApplication::qpeDir() + "plugins/styles/themes";
00090 QStringList list = QDir ( path, "*.themerc" ). entryList ( );
00091
00092 for ( QStringList::Iterator it = list. begin(); it != list. end ( ); ++it ) {
00093 MyConfig cfg ( path + "/" + *it, Config::File );
00094
00095 if ( cfg. hasGroup ( "Misc" )) {
00096 cfg. setGroup ( "Misc" );
00097
00098 QString name = cfg. readEntry ( "Name" );
00099 QString comm = cfg. readEntry ( "Comment" );
00100
00101 if ( !name. isEmpty ( )) {
00102 QString fname = (*it). left ((*it). length ( ) - 8 );
00103
00104 item = new MyItem ( m_list, item, name, comm, fname );
00105 if ( active == fname ) {
00106 m_list-> setSelected ( item, true );
00107 }
00108 }
00109 }
00110 }
00111 }
00112
00113 bool ThemeSettings::writeConfig ( )
00114 {
00115 Config config ( "qpe" );
00116 config. setGroup ( "Appearance" );
00117
00118 MyItem *it = (MyItem *) m_list-> selectedItem ( );
00119 config. writeEntry ( "Theme", it ? it-> m_theme : QString ( "" ));
00120 config. write ( );
00121
00122 return true;
00123 }
00124