Diffstat (limited to 'core/pim/datebook/holiday/national/nationalcfgwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfgwidget.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.cpp b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp new file mode 100644 index 0000000..6e3dd7d --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp | |||
@@ -0,0 +1,99 @@ | |||
1 | #include "nationalcfgwidget.h" | ||
2 | |||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | #include <qpe/config.h> | ||
6 | #include <qpe/qpeapplication.h> | ||
7 | |||
8 | #include <qheader.h> | ||
9 | #include <qlabel.h> | ||
10 | #include <qlistview.h> | ||
11 | #include <qpushbutton.h> | ||
12 | #include <qlayout.h> | ||
13 | #include <qvariant.h> | ||
14 | #include <qtooltip.h> | ||
15 | #include <qwhatsthis.h> | ||
16 | #include <qheader.h> | ||
17 | #include <qdir.h> | ||
18 | |||
19 | /* | ||
20 | * Constructs a NationalHolidayConfig which is a child of 'parent', with the | ||
21 | * name 'name' and widget flags set to 'f' | ||
22 | */ | ||
23 | NationalHolidayConfigWidget::NationalHolidayConfigWidget( QWidget* parent, const char* name, WFlags fl ) | ||
24 | : Opie::Datebook::HolidayPluginConfigWidget( parent, name, fl ) | ||
25 | { | ||
26 | if ( !name ) | ||
27 | setName( "NationalHolidayConfig" ); | ||
28 | resize( 206, 210 ); | ||
29 | setCaption( tr( "Select national config" ) ); | ||
30 | NationalHolidayConfigLayout = new QVBoxLayout( this ); | ||
31 | NationalHolidayConfigLayout->setSpacing( 2 ); | ||
32 | NationalHolidayConfigLayout->setMargin( 2 ); | ||
33 | |||
34 | m_headLabel = new QLabel( this, "m_headLabel" ); | ||
35 | m_headLabel->setText( tr( "Select one or more configs to load" ) ); | ||
36 | m_headLabel->setAlignment( int( QLabel::AlignCenter ) ); | ||
37 | NationalHolidayConfigLayout->addWidget( m_headLabel ); | ||
38 | |||
39 | m_Configlist = new QListView( this, "m_Configlist" ); | ||
40 | m_Configlist->addColumn( tr( "configfiles" ) ); | ||
41 | QWhatsThis::add( m_Configlist, tr( "List of found xml-files which may load." ) ); | ||
42 | NationalHolidayConfigLayout->addWidget( m_Configlist ); | ||
43 | |||
44 | // signals and slots connections | ||
45 | connect( m_Configlist, SIGNAL( clicked(QListViewItem*) ), this, SLOT( listItemClicked(QListViewItem*) ) ); | ||
46 | init(); | ||
47 | } | ||
48 | |||
49 | void NationalHolidayConfigWidget::init() | ||
50 | { | ||
51 | m_Configlist->header()->hide(); | ||
52 | m_Configlist->setSorting(-1); | ||
53 | |||
54 | QString path = QPEApplication::qpeDir() + "etc/nationaldays"; | ||
55 | QDir dir( path, "*.xml" ); | ||
56 | QStringList list = dir.entryList(); | ||
57 | QStringList::Iterator it; | ||
58 | Config cfg("nationaldays"); | ||
59 | cfg.setGroup("entries"); | ||
60 | files = cfg.readListEntry("files"); | ||
61 | QCheckListItem *pitem = 0; | ||
62 | |||
63 | for (it=list.begin();it!=list.end();++it) { | ||
64 | pitem = new QCheckListItem(m_Configlist,(*it),QCheckListItem::CheckBox); | ||
65 | if (files.find((*it)) != files.end()) { | ||
66 | pitem->setOn(true); | ||
67 | } else { | ||
68 | pitem->setOn(false); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
73 | /* | ||
74 | * Destroys the object and frees any allocated resources | ||
75 | */ | ||
76 | NationalHolidayConfigWidget::~NationalHolidayConfigWidget() | ||
77 | { | ||
78 | // no need to delete child widgets, Qt does it all for us | ||
79 | } | ||
80 | |||
81 | void NationalHolidayConfigWidget::listItemClicked(QListViewItem*item) | ||
82 | { | ||
83 | if (!item) return; | ||
84 | QCheckListItem*pitem = ((QCheckListItem*)item); | ||
85 | QStringList::Iterator it = files.find(pitem->text(0)); | ||
86 | if (pitem->isOn()&&it==files.end()) { | ||
87 | files.append(pitem->text(0)); | ||
88 | } else if (!pitem->isOn() && it!=files.end()) { | ||
89 | files.remove(it); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | void NationalHolidayConfigWidget::saveConfig() | ||
94 | { | ||
95 | Config cfg("nationaldays"); | ||
96 | cfg.setGroup("entries"); | ||
97 | cfg.writeEntry("files",files); | ||
98 | } | ||
99 | |||