summaryrefslogtreecommitdiffabout
path: root/libkdepim
Unidiff
Diffstat (limited to 'libkdepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/addresseeview.cpp282
-rw-r--r--libkdepim/addresseeview.h60
-rw-r--r--libkdepim/categoryeditdialog.cpp135
-rw-r--r--libkdepim/categoryeditdialog.h62
-rw-r--r--libkdepim/categoryeditdialog.moc0
-rw-r--r--libkdepim/categoryeditdialog_base.cpp154
-rw-r--r--libkdepim/categoryeditdialog_base.h58
-rw-r--r--libkdepim/categoryeditdialog_base.moc0
-rw-r--r--libkdepim/categoryselectdialog.cpp173
-rw-r--r--libkdepim/categoryselectdialog.h69
-rw-r--r--libkdepim/categoryselectdialog.moc0
-rw-r--r--libkdepim/categoryselectdialog_base.cpp128
-rw-r--r--libkdepim/categoryselectdialog_base.h53
-rw-r--r--libkdepim/categoryselectdialog_base.moc0
-rw-r--r--libkdepim/kdateedit.cpp486
-rw-r--r--libkdepim/kdateedit.h140
-rw-r--r--libkdepim/kdateedit.moc0
-rw-r--r--libkdepim/kdatepicker.cpp472
-rw-r--r--libkdepim/kdatepicker.h181
-rw-r--r--libkdepim/kdatepicker.moc0
-rw-r--r--libkdepim/kdepim.pro.back34
-rw-r--r--libkdepim/kincidenceformatter.cpp326
-rw-r--r--libkdepim/kincidenceformatter.h42
-rw-r--r--libkdepim/kinputdialog.cpp14
-rw-r--r--libkdepim/kinputdialog.h15
-rw-r--r--libkdepim/kpimprefs.cpp59
-rw-r--r--libkdepim/kpimprefs.h53
-rw-r--r--libkdepim/kprefs.cpp463
-rw-r--r--libkdepim/kprefs.h301
-rw-r--r--libkdepim/kprefsdialog.cpp410
-rw-r--r--libkdepim/kprefsdialog.h446
-rw-r--r--libkdepim/kprefsdialog.moc0
-rw-r--r--libkdepim/ksyncprofile.cpp125
-rw-r--r--libkdepim/ksyncprofile.h106
-rw-r--r--libkdepim/libkdepim.pro50
-rw-r--r--libkdepim/libkdepimE.pro43
36 files changed, 4940 insertions, 0 deletions
diff --git a/libkdepim/addresseeview.cpp b/libkdepim/addresseeview.cpp
new file mode 100644
index 0000000..deafd34
--- a/dev/null
+++ b/libkdepim/addresseeview.cpp
@@ -0,0 +1,282 @@
1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22#include <kabc/address.h>
23#include <kabc/addressee.h>
24#include <kabc/phonenumber.h>
25#include <kglobal.h>
26//US#include <kglobalsettings.h>
27#include <kiconloader.h>
28#include <klocale.h>
29//US #include <kstringhandler.h>
30#include <qscrollview.h>
31#include <qregexp.h>
32#include <qfile.h>
33#include <qapplication.h>
34
35
36#include "addresseeview.h"
37
38using namespace KPIM;
39
40AddresseeView::AddresseeView( QWidget *parent, const char *name )
41//US : KTextBrowser( parent, name )
42 : QTextBrowser( parent, name )
43
44
45{
46//US setWrapPolicy( QTextEdit::AtWordBoundary );
47 setLinkUnderline( false );
48 // setVScrollBarMode( QScrollView::AlwaysOff );
49 //setHScrollBarMode( QScrollView::AlwaysOff );
50
51//US QStyleSheet *sheet = styleSheet();
52//US QStyleSheetItem *link = sheet->item( "a" );
53//US link->setColor( KGlobalSettings::linkColor() );
54
55}
56
57void AddresseeView::setAddressee( const KABC::Addressee& addr )
58{
59 mAddressee = addr;
60
61 // clear view
62 setText( QString::null );
63
64 if ( mAddressee.isEmpty() )
65 return;
66
67 QString name = ( mAddressee.formattedName().isEmpty() ?
68 mAddressee.assembledName() : mAddressee.formattedName() );
69
70 QString dynamicPart;
71
72 KABC::PhoneNumber::List phones = mAddressee.phoneNumbers();
73 KABC::PhoneNumber::List::ConstIterator phoneIt;
74 for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
75 dynamicPart += QString(
76 "<tr><td align=\"right\"><b>%1</b></td>"
77 "<td align=\"left\">%2</td></tr>" )
78 .arg( KABC::PhoneNumber::typeLabel( (*phoneIt).type() ) )
79 .arg( (*phoneIt).number() );
80 }
81
82 QStringList emails = mAddressee.emails();
83 QStringList::ConstIterator emailIt;
84 QString type = i18n( "Email" );
85 for ( emailIt = emails.begin(); emailIt != emails.end(); ++emailIt ) {
86 dynamicPart += QString(
87 "<tr><td align=\"right\"><b>%1</b></td>"
88 "<td align=\"left\"><a href=\"mailto:%2\">%3</a></td></tr>" )
89 .arg( type )
90 .arg( *emailIt )
91 .arg( *emailIt );
92 type = i18n( "Other" );
93 }
94
95 if ( !mAddressee.url().url().isEmpty() ) {
96 dynamicPart += QString(
97 "<tr><td align=\"right\"><b>%1</b></td>"
98 "<td align=\"left\">%2</td></tr>" )
99 .arg( i18n( "Homepage" ) )
100//US .arg( KStringHandler::tagURLs( mAddressee.url().url() ) );
101 .arg( mAddressee.url().url() );
102 //qDebug("AddresseeView::setAddressee has to be verified.");
103 }
104
105 KABC::Address::List addresses = mAddressee.addresses();
106 KABC::Address::List::ConstIterator addrIt;
107 for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
108 if ( true /*(*addrIt).label().isEmpty()*/ ) {
109 QString formattedAddress = (*addrIt).formattedAddress().stripWhiteSpace();
110//US formattedAddress = formattedAddress.replace( '\n', "<br>" );
111 //qDebug("adresss %s ",formattedAddress.latin1() );
112 formattedAddress = formattedAddress.replace( QRegExp("\n"), "<br>" );
113 //qDebug("AddresseeView::setAddressee has to be verified.");
114
115 dynamicPart += QString(
116 "<tr><td align=\"right\"><b>%1</b></td>"
117 "<td align=\"left\">%2</td></tr>" )
118 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
119 .arg( formattedAddress );
120 } else {
121
122 dynamicPart += QString(
123 "<tr><td align=\"right\"><b>%1</b></td>"
124 "<td align=\"left\">%2</td></tr>" )
125 .arg( KABC::Address::typeLabel( (*addrIt).type() ) )
126//US .arg( (*addrIt).label().replace( '\n', "<br>" ) );
127 .arg( (*addrIt).label() /*replace( QRegExp("\n"), "<br>" )*/ );
128
129 }
130 }
131
132 QString notes;
133 if ( !mAddressee.note().isEmpty() ) {
134 notes = QString(
135 "<tr>"
136 "<td align=\"right\" valign=\"top\"><b>%1:</b></td>" // note label
137 "<td align=\"left\">%2</td>" // note
138 "</tr>" ).arg( i18n( "Notes" ) )
139//US .arg( mAddressee.note().replace( '\n', "<br>" ) );
140 .arg( mAddressee.note().replace( QRegExp("\n"), "<br>" ) );
141 //qDebug("AddresseeView::setAddressee has to be verified.");
142 }
143
144 QString aRole = "";
145 QString aOrga = "";
146 if ( true /*!mAddressee.role().isEmpty()*/ ) {
147 aRole = "<tr>"
148 "<td align=\"left\">" + mAddressee.role() + "</td>"
149 "</tr>";
150 }
151 if ( true /*!mAddressee.organization().isEmpty()*/ ) {
152 aOrga = "<tr>"
153 "<td align=\"left\">" + mAddressee.organization() + "</td>" ;
154 "</tr>";
155 }
156 mText = "";
157 QString picString = "";
158 KABC::Picture picture = mAddressee.photo();
159 bool picAvailintern = false;
160 bool picAvailUrl = false;
161 if (! picture.undefined() ) {
162 picAvailintern = (picture.isIntern() && !picture.data().isNull());
163 picAvailUrl = !picture.isIntern() && QFile::exists(picture.url() );
164 }
165 if ( picAvailUrl || picAvailintern || QApplication::desktop()->width() > 320 ) {
166 if ( picAvailintern ) {
167 QMimeSourceFactory::defaultFactory()->setImage( "myimage", picture.data() );
168 } else {
169 if ( picAvailUrl ) {
170 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", QPixmap( picture.url() ));
171 } else {
172 QMimeSourceFactory::defaultFactory()->setPixmap( "myimage", KGlobal::iconLoader()->loadIcon( "package_toys", KIcon::Desktop, 128 ) );
173 }
174 }
175 picString = "<img src=\"myimage\" width=\"50\" height=\"70\">";
176 mText = QString::fromLatin1(
177 "<html>"
178 "<body text=\"%1\" bgcolor=\"%2\">" // text and background color
179 "<table>"
180 "<tr>"
181 "<td rowspan=\"3\" align=\"right\" valign=\"top\">"
182 "%3"
183 "</td>"
184 "<td align=\"left\"><font size=\"+2\"><b>%4</b></font></td>" // name
185 "</tr>"
186 "%5" // role
187 "%6" // organization
188 "<td colspan=\"2\">&nbsp;</td>"
189 "%7" // dynamic part
190 "%8" // notes
191 "</table>"
192 "</body>"
193 "</html>")
194//US
195 .arg( /*KGlobalSettings::textColor().name()*/ "black" )
196//US
197 .arg( /*KGlobalSettings::baseColor().name()*/ "white" )
198 .arg( picString )
199 .arg( name )
200 .arg( aRole )
201 .arg( aOrga )
202 .arg( dynamicPart )
203 .arg( notes );
204
205 } else { // no picture!
206
207mText = "<table width=\"100%\">\n";
208 //mText += "<tr bgcolor=\"#3679AD\"><td><h2>";
209#ifdef DESKTOP_VERSION
210 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h1>";
211#else
212 mText += "<tr bgcolor=\"#5699CD\"><td align=\"left\"><h2>";
213#endif
214
215#ifdef DESKTOP_VERSION
216 mText += "<font color=\"#FFFFFF\"> <em>" + name+"</em></font></h1>";
217#else
218 mText += "<font color=\"#FFFFFF\"> <em>" + name +"</em></font></h2>";
219#endif
220 mText += "</td></tr>\n<tr bgcolor=\"#EAF8FA\"><td>";
221
222 mText += "<table><td colspan=\"2\">&nbsp;</td>";
223 /*
224 mText += QString("<tr><td align=\"right\"><b2>%1</b2></td>"
225 "<td align=\"left\"><b>%2</b></td></tr>" )
226 .arg( i18n(" ") )
227 .arg( name );
228 */
229 if ( ! mAddressee.role().isEmpty() )
230 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
231 "<td align=\"left\">%2</td></tr>" )
232 .arg( i18n(" ") )
233 .arg( mAddressee.role());
234 if ( ! mAddressee.organization().isEmpty() )
235 mText += QString("<tr><td align=\"right\"><b>%1</b></td>"
236 "<td align=\"left\">%2</td></tr>" )
237 .arg( i18n(" ") )
238 .arg( mAddressee.organization());
239 mText += dynamicPart;
240 mText += notes;
241 mText += "</table>";
242
243 }
244
245 // at last display it...
246 setText( mText );
247}
248
249KABC::Addressee AddresseeView::addressee() const
250{
251 return mAddressee;
252}
253void AddresseeView::addTag(const QString & tag,const QString & text)
254{
255 if ( text.isEmpty() )
256 return;
257 int number=text.contains("\n");
258 QString str = "<" + tag + ">";
259 QString tmpText=text;
260 QString tmpStr=str;
261 if(number !=-1)
262 {
263 if (number > 0) {
264 int pos=0;
265 QString tmp;
266 for(int i=0;i<=number;i++) {
267 pos=tmpText.find("\n");
268 tmp=tmpText.left(pos);
269 tmpText=tmpText.right(tmpText.length()-pos-1);
270 tmpStr+=tmp+"<br>";
271 }
272 }
273 else tmpStr += tmpText;
274 tmpStr+="</" + tag + ">";
275 mText.append(tmpStr);
276 }
277 else
278 {
279 str += text + "</" + tag + ">";
280 mText.append(str);
281 }
282}
diff --git a/libkdepim/addresseeview.h b/libkdepim/addresseeview.h
new file mode 100644
index 0000000..598ef0d
--- a/dev/null
+++ b/libkdepim/addresseeview.h
@@ -0,0 +1,60 @@
1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22#ifndef KPIM_ADDRESSEEVIEW_H
23#define KPIM_ADDRESSEEVIEW_H
24
25#include <kabc/addressee.h>
26
27//US #include <ktextbrowser.h>
28#include <qtextbrowser.h>
29
30namespace KPIM {
31
32//US class AddresseeView : public KTextBrowser
33class AddresseeView : public QTextBrowser
34{
35 public:
36 AddresseeView( QWidget *parent = 0, const char *name = 0 );
37
38 /**
39 Sets the addressee object. The addressee is displayed immediately.
40
41 @param addr The addressee object.
42 */
43 void setAddressee( const KABC::Addressee& addr );
44
45 /**
46 Returns the current addressee object.
47 */
48 KABC::Addressee addressee() const;
49
50 private:
51 KABC::Addressee mAddressee;
52 QString mText;
53 void addTag(const QString & tag,const QString & text);
54 class AddresseeViewPrivate;
55 AddresseeViewPrivate *d;
56};
57
58}
59
60#endif
diff --git a/libkdepim/categoryeditdialog.cpp b/libkdepim/categoryeditdialog.cpp
new file mode 100644
index 0000000..87172c1
--- a/dev/null
+++ b/libkdepim/categoryeditdialog.cpp
@@ -0,0 +1,135 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qstringlist.h>
25#include <qlineedit.h>
26#include <qlistview.h>
27#include <qheader.h>
28#include <qpushbutton.h>
29#include <qapplication.h>
30
31#include "kpimprefs.h"
32
33#include "categoryeditdialog.h"
34
35using namespace KPIM;
36
37CategoryEditDialog::CategoryEditDialog( KPimPrefs *prefs, QWidget* parent,
38 const char* name, bool modal,
39 WFlags fl )
40 : CategoryEditDialog_base( parent, name, modal, fl ),
41 mPrefs( prefs )
42{
43 mCategories->header()->hide();
44
45 QStringList::Iterator it;
46 bool categoriesExist=false;
47 for (it = mPrefs->mCustomCategories.begin();
48 it != mPrefs->mCustomCategories.end(); ++it ) {
49 new QListViewItem(mCategories,*it);
50 categoriesExist=true;
51 }
52
53 connect(mCategories,SIGNAL(selectionChanged(QListViewItem *)),
54 SLOT(editItem(QListViewItem *)));
55 connect(mEdit,SIGNAL(textChanged ( const QString & )),this,SLOT(slotTextChanged(const QString &)));
56 mButtonRemove->setEnabled(categoriesExist);
57 mButtonModify->setEnabled(categoriesExist);
58 mButtonAdd->setEnabled(!mEdit->text().isEmpty());
59 if ( QApplication::desktop()->width() > 460 )
60 resize( 300, 360 );
61}
62
63/*
64 * Destroys the object and frees any allocated resources
65 */
66CategoryEditDialog::~CategoryEditDialog()
67{
68 // no need to delete child widgets, Qt does it all for us
69}
70
71void CategoryEditDialog::slotTextChanged(const QString &text)
72{
73 mButtonAdd->setEnabled(!text.isEmpty());
74}
75
76void CategoryEditDialog::add()
77{
78 if (!mEdit->text().isEmpty()) {
79 new QListViewItem(mCategories,mEdit->text());
80 mEdit->setText("");
81 mButtonRemove->setEnabled(mCategories->childCount()>0);
82 mButtonModify->setEnabled(mCategories->childCount()>0);
83 }
84}
85
86void CategoryEditDialog::remove()
87{
88 if (mCategories->currentItem()) {
89 delete mCategories->currentItem();
90 mButtonRemove->setEnabled(mCategories->childCount()>0);
91 mButtonModify->setEnabled(mCategories->childCount()>0);
92 }
93}
94
95void CategoryEditDialog::modify()
96{
97 if (!mEdit->text().isEmpty()) {
98 if (mCategories->currentItem()) {
99 mCategories->currentItem()->setText(0,mEdit->text());
100 }
101 }
102}
103void CategoryEditDialog::accept()
104{
105 slotOk();
106}
107
108void CategoryEditDialog::slotOk()
109{
110 slotApply();
111 QDialog::accept();
112}
113
114void CategoryEditDialog::slotApply()
115{
116 mPrefs->mCustomCategories.clear();
117
118 QListViewItem *item = mCategories->firstChild();
119 while(item) {
120 mPrefs->mCustomCategories.append(item->text(0));
121 item = item->nextSibling();
122 }
123 mPrefs->writeConfig();
124
125 emit categoryConfigChanged();
126}
127
128void CategoryEditDialog::editItem(QListViewItem *item)
129{
130 mEdit->setText(item->text(0));
131 mButtonRemove->setEnabled(true);
132 mButtonModify->setEnabled(true);
133}
134
135#include "categoryeditdialog.moc"
diff --git a/libkdepim/categoryeditdialog.h b/libkdepim/categoryeditdialog.h
new file mode 100644
index 0000000..027cb98
--- a/dev/null
+++ b/libkdepim/categoryeditdialog.h
@@ -0,0 +1,62 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#ifndef KPIM_CATEGORYEDITDIALOG_H
24#define KPIM_CATEGORYEDITDIALOG_H
25
26#include <libkdepim/categoryeditdialog_base.h>
27
28class KPimPrefs;
29
30namespace KPIM {
31
32class CategoryEditDialog : public CategoryEditDialog_base
33{
34 Q_OBJECT
35 public:
36 CategoryEditDialog( KPimPrefs *prefs, QWidget* parent = 0,
37 const char* name = 0,
38 bool modal = FALSE, WFlags fl = 0 );
39 ~CategoryEditDialog();
40
41 public slots:
42 void add();
43 void remove();
44 void modify();
45 void accept();
46
47 void slotOk();
48 void slotApply();
49
50 signals:
51 void categoryConfigChanged();
52
53 private slots:
54 void editItem(QListViewItem *item);
55 void slotTextChanged(const QString &text);
56
57 KPimPrefs *mPrefs;
58};
59
60}
61
62#endif
diff --git a/libkdepim/categoryeditdialog.moc b/libkdepim/categoryeditdialog.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/categoryeditdialog.moc
diff --git a/libkdepim/categoryeditdialog_base.cpp b/libkdepim/categoryeditdialog_base.cpp
new file mode 100644
index 0000000..ac99190
--- a/dev/null
+++ b/libkdepim/categoryeditdialog_base.cpp
@@ -0,0 +1,154 @@
1#include <klocale.h>
2/****************************************************************************
3** Form implementation generated from reading ui file '/build/kde/cvs/korge/kdepim/libkdepim/categoryeditdialog_base.ui'
4**
5** Created: Sat Mar 29 21:46:09 2003
6** by: The User Interface Compiler ()
7**
8** WARNING! All changes made in this file will be lost!
9****************************************************************************/
10
11#include "categoryeditdialog_base.h"
12
13#include <qvariant.h>
14#include <qheader.h>
15#include <qlineedit.h>
16#include <qlistview.h>
17#include <qpushbutton.h>
18#include <qlayout.h>
19#include <qtooltip.h>
20#include <qwhatsthis.h>
21
22/*
23 * Constructs a CategoryEditDialog_base as a child of 'parent', with the
24 * name 'name' and widget flags set to 'f'.
25 *
26 * The dialog will by default be modeless, unless you set 'modal' to
27 * TRUE to construct a modal dialog.
28 */
29CategoryEditDialog_base::CategoryEditDialog_base( QWidget* parent, const char* name, bool modal, WFlags fl )
30 : QDialog( parent, name, true, fl )
31
32{
33 if ( !name )
34 setName( "CategoryEditDialog_base" );
35 CategoryEditDialog_baseLayout = new QGridLayout( this, 1, 1, 11, 6, "CategoryEditDialog_baseLayout");
36
37 mEdit = new QLineEdit( this, "mEdit" );
38
39 CategoryEditDialog_baseLayout->addMultiCellWidget( mEdit, 1, 1, 0, 1 );
40
41 Layout13 = new QHBoxLayout( 0, 0, 6, "Layout13");
42
43 // mButtonHelp = new QPushButton( this, "mButtonHelp" );
44 //mButtonHelp->setAutoDefault( TRUE );
45 //Layout13->addWidget( mButtonHelp );
46 //QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
47 //Layout13->addItem( spacer );
48
49 //mApply = new QPushButton( this, "mApply" );
50 // Layout13->addWidget( mApply );
51
52 mButtonOk = new QPushButton( this, "mButtonOk" );
53 mButtonOk->setAutoDefault( TRUE );
54 mButtonOk->setDefault( TRUE );
55 Layout13->addWidget( mButtonOk );
56
57 mButtonCancel = new QPushButton( this, "mButtonCancel" );
58 mButtonCancel->setAutoDefault( TRUE );
59 Layout13->addWidget( mButtonCancel );
60
61 CategoryEditDialog_baseLayout->addMultiCellLayout( Layout13, 2, 2, 0, 1 );
62
63 mCategories = new QListView( this, "mCategories" );
64 mCategories->addColumn( tr2i18n( "Category" ) );
65
66 CategoryEditDialog_baseLayout->addWidget( mCategories, 0, 0 );
67
68 layout103 = new QVBoxLayout( 0, 0, 6, "layout103");
69
70 mButtonAdd = new QPushButton( this, "mButtonAdd" );
71 layout103->addWidget( mButtonAdd );
72
73 mButtonModify = new QPushButton( this, "mButtonModify" );
74 layout103->addWidget( mButtonModify );
75
76 mButtonRemove = new QPushButton( this, "mButtonRemove" );
77 layout103->addWidget( mButtonRemove );
78 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
79 layout103->addItem( spacer_2 );
80
81 CategoryEditDialog_baseLayout->addLayout( layout103, 0, 1 );
82 languageChange();
83 resize( sizeHint() );
84
85 // signals and slots connections
86 connect( mButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
87 connect( mButtonAdd, SIGNAL( clicked() ), this, SLOT( add() ) );
88 connect( mButtonModify, SIGNAL( clicked() ), this, SLOT( modify() ) );
89 connect( mButtonRemove, SIGNAL( clicked() ), this, SLOT( remove() ) );
90 connect( mButtonOk, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
91 //connect( mApply, SIGNAL( clicked() ), this, SLOT( slotApply() ) );
92
93 // tab order
94 // setTabOrder( mCategories, mEdit );
95// setTabOrder( mEdit, mButtonAdd );
96// setTabOrder( mButtonAdd, mButtonModify );
97// setTabOrder( mButtonModify, mButtonRemove );
98// setTabOrder( mButtonRemove, mButtonHelp );
99// setTabOrder( mButtonHelp, mApply );
100// setTabOrder( mApply, mButtonOk );
101// setTabOrder( mButtonOk, mButtonCancel );
102}
103
104/*
105 * Destroys the object and frees any allocated resources
106 */
107CategoryEditDialog_base::~CategoryEditDialog_base()
108{
109 // no need to delete child widgets, Qt does it all for us
110}
111
112/*
113 * Sets the strings of the subwidgets using the current
114 * language.
115 */
116void CategoryEditDialog_base::languageChange()
117{
118 setCaption( tr2i18n( "Edit Categories" ) );
119 // mButtonHelp->setText( tr2i18n( "&Help" ) );
120 // mApply->setText( tr2i18n( "&Apply" ) );
121 mButtonOk->setText( tr2i18n( "&OK" ) );
122 mButtonCancel->setText( tr2i18n( "&Cancel" ) );
123 mCategories->header()->setLabel( 0, tr2i18n( "Category" ) );
124 mButtonAdd->setText( tr2i18n( "A&dd" ) );
125 mButtonModify->setText( tr2i18n( "&Modify" ) );
126 mButtonRemove->setText( tr2i18n( "&Remove" ) );
127}
128
129void CategoryEditDialog_base::add()
130{
131 qWarning( "CategoryEditDialog_base::add(): Not implemented yet" );
132}
133
134void CategoryEditDialog_base::modify()
135{
136 qWarning( "CategoryEditDialog_base::modify(): Not implemented yet" );
137}
138
139void CategoryEditDialog_base::slotApply()
140{
141 qWarning( "CategoryEditDialog_base::slotApply(): Not implemented yet" );
142}
143
144void CategoryEditDialog_base::remove()
145{
146 qWarning( "CategoryEditDialog_base::remove(): Not implemented yet" );
147}
148
149void CategoryEditDialog_base::slotOk()
150{
151 qWarning( "CategoryEditDialog_base::slotOk(): Not implemented yet" );
152}
153
154#include "categoryeditdialog_base.moc"
diff --git a/libkdepim/categoryeditdialog_base.h b/libkdepim/categoryeditdialog_base.h
new file mode 100644
index 0000000..5557ad0
--- a/dev/null
+++ b/libkdepim/categoryeditdialog_base.h
@@ -0,0 +1,58 @@
1/****************************************************************************
2** Form interface generated from reading ui file '/build/kde/cvs/korge/kdepim/libkdepim/categoryeditdialog_base.ui'
3**
4** Created: Sat Mar 29 21:45:20 2003
5** by: The User Interface Compiler ()
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef CATEGORYEDITDIALOG_BASE_H
11#define CATEGORYEDITDIALOG_BASE_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QLineEdit;
20class QListView;
21class QListViewItem;
22class QPushButton;
23
24class CategoryEditDialog_base : public QDialog
25{
26 Q_OBJECT
27
28public:
29 CategoryEditDialog_base( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
30 ~CategoryEditDialog_base();
31
32 QLineEdit* mEdit;
33 QPushButton* mButtonHelp;
34 QPushButton* mApply;
35 QPushButton* mButtonOk;
36 QPushButton* mButtonCancel;
37 QListView* mCategories;
38 QPushButton* mButtonAdd;
39 QPushButton* mButtonModify;
40 QPushButton* mButtonRemove;
41
42public slots:
43 virtual void add();
44 virtual void modify();
45 virtual void slotApply();
46 virtual void remove();
47 virtual void slotOk();
48
49protected:
50 QGridLayout* CategoryEditDialog_baseLayout;
51 QHBoxLayout* Layout13;
52 QVBoxLayout* layout103;
53
54protected slots:
55 virtual void languageChange();
56};
57
58#endif // CATEGORYEDITDIALOG_BASE_H
diff --git a/libkdepim/categoryeditdialog_base.moc b/libkdepim/categoryeditdialog_base.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/categoryeditdialog_base.moc
diff --git a/libkdepim/categoryselectdialog.cpp b/libkdepim/categoryselectdialog.cpp
new file mode 100644
index 0000000..7b0aced
--- a/dev/null
+++ b/libkdepim/categoryselectdialog.cpp
@@ -0,0 +1,173 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <qlistview.h>
25#include <qpushbutton.h>
26#include <qheader.h>
27#include <qapp.h>
28#include <qmessagebox.h>
29
30
31#include <libkdepim/categoryeditdialog.h>
32#include "categoryselectdialog.h"
33
34#include "kpimprefs.h"
35
36using namespace KPIM;
37
38CategorySelectDialog::CategorySelectDialog( KPimPrefs *prefs, QWidget* parent,
39 const char* name,
40 bool modal, WFlags fl )
41 : CategorySelectDialog_base( parent, name, true, fl ),
42 mPrefs( prefs )
43{
44 mCategories->header()->hide();
45
46 setCategories();
47
48 connect(mButtonEdit,SIGNAL(clicked()),this, SLOT(editCategoriesDialog()));
49 if ( qApp->desktop()->height() < 321 )
50 setMaximumHeight( QApplication::desktop()->height() - 50 );
51 else
52 setMaximumHeight( QApplication::desktop()->height() - 80 );
53 if ( QApplication::desktop()->width() > 460 )
54 resize( 260, 360 );
55}
56void CategorySelectDialog::editCategoriesDialog()
57{
58 KPIM::CategoryEditDialog* ced = new KPIM::CategoryEditDialog(mPrefs,this );
59
60 ced->exec();
61 delete ced;
62 setCategories();
63}
64void CategorySelectDialog::setCategories()
65{
66 mCategories->clear();
67 mCategoryList.clear();
68
69 QStringList::Iterator it;
70
71 for (it = mPrefs->mCustomCategories.begin();
72 it != mPrefs->mCustomCategories.end(); ++it ) {
73 new QCheckListItem(mCategories,*it,QCheckListItem::CheckBox);
74 }
75}
76
77CategorySelectDialog::~CategorySelectDialog()
78{
79}
80
81void CategorySelectDialog::setSelected(const QStringList &selList)
82{
83 clear();
84
85 QStringList::ConstIterator it;
86 QStringList notFound;
87 bool found = false;
88 for (it=selList.begin();it!=selList.end();++it) {
89 //qDebug(" CategorySelectDialog::setSelected(");
90 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
91 while (item) {
92 if (item->text() == *it) {
93 item->setOn(true);
94 found = true;
95 break;
96 }
97 item = (QCheckListItem *)item->nextSibling();
98 }
99// if ( ! found ) {
100
101//emit updateCategoriesGlobal();
102// QMessageBox::information( this, "KO/E: Information!",
103// "Categories found, which were not\n"
104// "in list of categories!\n"
105// "message",
106// "OK", "", 0,
107// 0, 1 );
108// setSelected(selList);
109// return;
110// }
111 }
112}
113
114QStringList CategorySelectDialog::selectedCategories() const
115{
116 return mCategoryList;
117}
118
119void CategorySelectDialog::slotApply()
120{
121 QStringList categories;
122 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
123 while (item) {
124 if (item->isOn()) {
125 categories.append(item->text());
126 }
127 item = (QCheckListItem *)item->nextSibling();
128 }
129
130 QString categoriesStr = categories.join(",");
131
132 mCategoryList = categories;
133
134 emit categoriesSelected(categories);
135 emit categoriesSelected(categoriesStr);
136}
137void CategorySelectDialog::accept()
138{
139 slotOk();
140}
141
142void CategorySelectDialog::slotOk()
143{
144 slotApply();
145 QDialog::accept();
146}
147
148void CategorySelectDialog::clear()
149{
150 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
151 while (item) {
152 item->setOn(false);
153 item = (QCheckListItem *)item->nextSibling();
154 }
155}
156
157void CategorySelectDialog::updateCategoryConfig()
158{
159 QStringList selected;
160 QCheckListItem *item = (QCheckListItem *)mCategories->firstChild();
161 while (item) {
162 if (item->isOn()) {
163 selected.append(item->text());
164 }
165 item = (QCheckListItem *)item->nextSibling();
166 }
167
168 setCategories();
169
170 setSelected(selected);
171}
172
173#include "categoryselectdialog.moc"
diff --git a/libkdepim/categoryselectdialog.h b/libkdepim/categoryselectdialog.h
new file mode 100644
index 0000000..8507dc4
--- a/dev/null
+++ b/libkdepim/categoryselectdialog.h
@@ -0,0 +1,69 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2000, 2001, 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#ifndef KPIM_CATEGORYSELECTDIALOG_H
24#define KPIM_CATEGORYSELECTDIALOG_H
25
26#include <libkdepim/categoryselectdialog_base.h>
27
28class KPimPrefs;
29
30namespace KPIM {
31
32class CategorySelectDialog : public CategorySelectDialog_base
33{
34 Q_OBJECT
35 public:
36 CategorySelectDialog( KPimPrefs *prefs, QWidget* parent = 0,
37 const char* name = 0,
38 bool modal = FALSE, WFlags fl = 0 );
39 ~CategorySelectDialog();
40
41 void setCategories();
42 void setSelected(const QStringList &selList);
43
44 QStringList selectedCategories() const;
45
46 public slots:
47 void slotOk();
48 void slotApply();
49 void clear();
50 void accept();
51 void editCategoriesDialog();
52 void updateCategoryConfig();
53
54 signals:
55 void categoriesSelected(const QString &);
56 void categoriesSelected(const QStringList &);
57 void editCategories();
58
59 private:
60 KPimPrefs *mPrefs;
61 QStringList mCategoryList;
62
63 class CategorySelectDialogPrivate;
64 CategorySelectDialogPrivate *d;
65};
66
67}
68
69#endif
diff --git a/libkdepim/categoryselectdialog.moc b/libkdepim/categoryselectdialog.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/categoryselectdialog.moc
diff --git a/libkdepim/categoryselectdialog_base.cpp b/libkdepim/categoryselectdialog_base.cpp
new file mode 100644
index 0000000..5e5fa72
--- a/dev/null
+++ b/libkdepim/categoryselectdialog_base.cpp
@@ -0,0 +1,128 @@
1#include <klocale.h>
2/****************************************************************************
3** Form implementation generated from reading ui file '/build/kde/cvs/korge/kdepim/libkdepim/categoryselectdialog_base.ui'
4**
5** Created: Sat Mar 29 21:46:05 2003
6** by: The User Interface Compiler ()
7**
8** WARNING! All changes made in this file will be lost!
9****************************************************************************/
10
11#include "categoryselectdialog_base.h"
12
13#include <qvariant.h>
14#include <qheader.h>
15#include <qlistview.h>
16#include <qpushbutton.h>
17#include <qlayout.h>
18#include <qtooltip.h>
19#include <qwhatsthis.h>
20
21/*
22 * Constructs a CategorySelectDialog_base as a child of 'parent', with the
23 * name 'name' and widget flags set to 'f'.
24 *
25 * The dialog will by default be modeless, unless you set 'modal' to
26 * TRUE to construct a modal dialog.
27 */
28CategorySelectDialog_base::CategorySelectDialog_base( QWidget* parent, const char* name, bool modal, WFlags fl )
29 : QDialog( parent, name, modal, fl )
30
31{
32 if ( !name )
33 setName( "CategorySelectDialog_base" );
34 CategorySelectDialog_baseLayout = new QVBoxLayout( this, 11, 6, "CategorySelectDialog_baseLayout");
35
36 mCategories = new QListView( this, "mCategories" );
37 mCategories->addColumn( i18n( "Category" ) );
38 CategorySelectDialog_baseLayout->addWidget( mCategories );
39
40 Layout12 = new QHBoxLayout( 0, 0, 6, "Layout12");
41
42 mClear = new QPushButton( this, "mClear" );
43 Layout12->addWidget( mClear );
44 // QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
45 //Layout12->addItem( spacer );
46
47 mButtonEdit = new QPushButton( this, "mButtonEdit" );
48 Layout12->addWidget( mButtonEdit );
49 CategorySelectDialog_baseLayout->addLayout( Layout12 );
50
51 Layout11 = new QHBoxLayout( 0, 0, 6, "Layout11");
52
53 //mButtonHelp = new QPushButton( this, "mButtonHelp" );
54 //Layout11->addWidget( mButtonHelp );
55 //QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
56 // Layout11->addItem( spacer_2 );
57
58 //mApply = new QPushButton( this, "mApply" );
59 // Layout11->addWidget( mApply );
60
61 mButtonOk = new QPushButton( this, "mButtonOk" );
62 mButtonOk->setOn( FALSE );
63 mButtonOk->setDefault( TRUE );
64 Layout11->addWidget( mButtonOk );
65
66 mButtonCancel = new QPushButton( this, "mButtonCancel" );
67 Layout11->addWidget( mButtonCancel );
68 CategorySelectDialog_baseLayout->addLayout( Layout11 );
69 languageChange();
70 // resize( sizeHint() );
71
72 // signals and slots connections
73 connect( mButtonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
74 connect( mButtonOk, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
75 connect( mClear, SIGNAL( clicked() ), this, SLOT( clear() ) );
76 //connect( mApply, SIGNAL( clicked() ), this, SLOT( slotApply() ) );
77
78 // tab order
79 setTabOrder( mCategories, mClear );
80 setTabOrder( mClear, mButtonEdit );
81 setTabOrder( mButtonEdit, mButtonOk );//mButtonHelp );
82 // setTabOrder( mButtonHelp, mApply );
83 // setTabOrder( mApply, mButtonOk );
84 setTabOrder( mButtonOk, mButtonCancel );
85 // showMaximized();
86 //raise();
87}
88
89/*
90 * Destroys the object and frees any allocated resources
91 */
92CategorySelectDialog_base::~CategorySelectDialog_base()
93{
94 // no need to delete child widgets, Qt does it all for us
95}
96
97/*
98 * Sets the strings of the subwidgets using the current
99 * language.
100 */
101void CategorySelectDialog_base::languageChange()
102{
103 setCaption( i18n( "Select Categories" ) );
104 mCategories->header()->setLabel( 0, tr2i18n( "Category" ) );
105 mClear->setText( i18n( " &Deselect All " ) );
106 mButtonEdit->setText( i18n( " &Edit Categories " ) );
107 // mButtonHelp->setText( tr2i18n( "&Help" ) );
108 //mApply->setText( i18n( "&Apply" ) );
109 mButtonOk->setText( i18n( "&OK" ) );
110 mButtonCancel->setText( i18n( "&Cancel" ) );
111}
112
113void CategorySelectDialog_base::clear()
114{
115 qWarning( "CategorySelectDialog_base::clear(): Not implemented yet" );
116}
117
118void CategorySelectDialog_base::slotApply()
119{
120 qWarning( "CategorySelectDialog_base::slotApply(): Not implemented yet" );
121}
122
123void CategorySelectDialog_base::slotOk()
124{
125 qWarning( "CategorySelectDialog_base::slotOk(): Not implemented yet" );
126}
127
128#include "categoryselectdialog_base.moc"
diff --git a/libkdepim/categoryselectdialog_base.h b/libkdepim/categoryselectdialog_base.h
new file mode 100644
index 0000000..af905ed
--- a/dev/null
+++ b/libkdepim/categoryselectdialog_base.h
@@ -0,0 +1,53 @@
1/****************************************************************************
2** Form interface generated from reading ui file '/build/kde/cvs/korge/kdepim/libkdepim/categoryselectdialog_base.ui'
3**
4** Created: Sat Mar 29 21:45:20 2003
5** by: The User Interface Compiler ()
6**
7** WARNING! All changes made in this file will be lost!
8****************************************************************************/
9
10#ifndef CATEGORYSELECTDIALOG_BASE_H
11#define CATEGORYSELECTDIALOG_BASE_H
12
13#include <qvariant.h>
14#include <qdialog.h>
15
16class QVBoxLayout;
17class QHBoxLayout;
18class QGridLayout;
19class QListView;
20class QListViewItem;
21class QPushButton;
22
23class CategorySelectDialog_base : public QDialog
24{
25 Q_OBJECT
26
27public:
28 CategorySelectDialog_base( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
29 ~CategorySelectDialog_base();
30
31 QListView* mCategories;
32 QPushButton* mClear;
33 QPushButton* mButtonEdit;
34 QPushButton* mButtonHelp;
35 QPushButton* mApply;
36 QPushButton* mButtonOk;
37 QPushButton* mButtonCancel;
38
39public slots:
40 virtual void clear();
41 virtual void slotApply();
42 virtual void slotOk();
43
44protected:
45 QVBoxLayout* CategorySelectDialog_baseLayout;
46 QHBoxLayout* Layout12;
47 QHBoxLayout* Layout11;
48
49protected slots:
50 virtual void languageChange();
51};
52
53#endif // CATEGORYSELECTDIALOG_BASE_H
diff --git a/libkdepim/categoryselectdialog_base.moc b/libkdepim/categoryselectdialog_base.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/categoryselectdialog_base.moc
diff --git a/libkdepim/kdateedit.cpp b/libkdepim/kdateedit.cpp
new file mode 100644
index 0000000..60bd2cf
--- a/dev/null
+++ b/libkdepim/kdateedit.cpp
@@ -0,0 +1,486 @@
1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
23*/
24
25#include <qapplication.h>
26#include <qevent.h>
27#include <qlineedit.h>
28#include <qpixmap.h>
29#include <qpushbutton.h>
30
31#include <kdatepicker.h>
32#include <kdebug.h>
33#include <kglobal.h>
34#include <kiconloader.h>
35#include <klocale.h>
36#include <kmessagebox.h>
37#include <knotifyclient.h>
38#include <qpalette.h>
39
40#include "kdateedit.h"
41#include "kdateedit.moc"
42
43KDateEdit::KDateEdit(QWidget *parent, const char *name, bool withoutDP )
44 : QHBox(parent, name)
45{
46 dateFormShort = true;
47 withoutDp = withoutDP;
48 mDateEdit = new QLineEdit(this);
49 mDateEdit->setText(KGlobal::locale()->formatDate(QDate::currentDate(),dateFormShort));
50 setFocusProxy(mDateEdit);
51 mDateEdit->installEventFilter(this);
52
53 // Highlight Background and Textcolor
54 QPalette palette = QWidget::palette();
55 unsigned char red, green, blue;
56 red = palette.color( QPalette::Normal , QColorGroup::Background ).red() - 10;
57 green = palette.color( QPalette::Normal , QColorGroup::Background ).green() - 10;
58 blue = palette.color( QPalette::Normal , QColorGroup::Background ).blue() - 10;
59 palette.setColor( QColorGroup::Highlight, QColor(red,green,blue) );
60 palette.setColor( QColorGroup::HighlightedText, palette.color( QPalette::Normal , QColorGroup::Foreground ) );
61 mDateEdit->setPalette( palette );
62
63 if ( withoutDP ) {
64 mDateFrame = 0;
65 mDateButton = 0;
66 mDatePicker = 0;
67 } else {
68 QPixmap pixmap = SmallIcon("smallcal");
69 mDateButton = new QPushButton(this);
70 mDateButton->setPixmap(pixmap);
71
72 mDateFrame = new QVBox(0,0,WType_Popup);
73 // mDateFrame->setFrameStyle(QFrame::PopupPanel | QFrame::Raised);
74 mDateFrame->setFrameStyle( QFrame::WinPanel |QFrame::Raised );
75 mDateFrame->setLineWidth(3);
76 mDateFrame->hide();
77
78 mDatePicker = new KDatePicker(mDateFrame,QDate::currentDate());
79 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SLOT(setDate(QDate)));
80 connect(mDatePicker,SIGNAL(dateEntered(QDate)),SIGNAL(dateChanged(QDate)));
81 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SLOT(setDate(QDate)));
82 connect(mDatePicker,SIGNAL(dateSelected(QDate)),SIGNAL(dateChanged(QDate)));
83 connect(mDatePicker,SIGNAL(dateSelected(QDate)),mDateFrame,SLOT(hide()));
84 connect(mDateButton,SIGNAL(clicked()),SLOT(toggleDatePicker()));
85
86 //mDateFrame->resize( 400, 300 );
87
88 }
89 connect(mDateEdit,SIGNAL(returnPressed()),SLOT(lineEnterPressed()));
90 connect(mDateEdit,SIGNAL(textChanged(const QString &)),
91 SLOT(textChanged(const QString &)));
92
93 // Create the keyword list. This will be used to match against when the user
94 // enters information.
95 mKeywordMap[i18n("tomorrow")] = 1;
96 mKeywordMap[i18n("today")] = 0;
97 mKeywordMap[i18n("yesterday")] = -1;
98
99 /*
100 * This loop uses some math tricks to figure out the offset in days
101 * to the next date the given day of the week occurs. There
102 * are two cases, that the new day is >= the current day, which means
103 * the new day has not occured yet or that the new day < the current day,
104 * which means the new day is already passed (so we need to find the
105 * day in the next week).
106 */
107 QString dayName;
108 int currentDay = QDate::currentDate().dayOfWeek();
109 for (int i = 1; i <= 7; ++i)
110 {
111 dayName = KGlobal::locale()->weekDayName(i).lower();
112 if (i >= currentDay)
113 mKeywordMap[dayName] = i - currentDay;
114 else
115 mKeywordMap[dayName] = 7 - currentDay + i;
116 }
117
118 mTextChanged = false;
119 mHandleInvalid = false;
120 QWidget::setTabOrder( mDateEdit, mDateButton );
121}
122
123KDateEdit::~KDateEdit()
124{
125 delete mDateFrame;
126}
127
128void KDateEdit::setDate(QDate newDate)
129{
130 if (!newDate.isValid() && !mHandleInvalid)
131 return;
132 if ( readDate() == newDate )
133 return;
134 QString dateString = "";
135 if(newDate.isValid())
136 dateString = KGlobal::locale()->formatDate( newDate, dateFormShort );
137
138 mTextChanged = false;
139
140 // We do not want to generate a signal here, since we explicity setting
141 // the date
142 bool b = mDateEdit->signalsBlocked();
143 mDateEdit->blockSignals(true);
144 mDateEdit->setText(dateString);
145 mDateEdit->blockSignals(b);
146}
147
148void KDateEdit::setDate( QDate date,int *cpos,const int key ,const bool dateFormShort)
149{
150 QString dateForm = dateFormShort ?
151 KGlobal::locale()->dateFormatShort() :
152 KGlobal::locale()->dateFormat();
153
154 int begin = dateForm.find("%");
155 int space = 0;
156 int allStrLength = 0;
157 int strLength = 0;
158 int repeat = 0;
159
160 // witch? Day, Month or Year switch?
161 while(1){
162 switch ( dateForm.at(begin + 1).latin1() )
163 {
164 case 'd':// 16 (month day)
165 strLength = 2; //Ok
166 break;
167 case 'm':// 01 (month)
168 strLength = 2; //Ok
169 break;
170 case 'a':// Mon (Weekday)
171 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length();
172 break;
173 case 'A':// Monday (Weekday)
174 strLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length();
175 break;
176 case 'b':// Jan (monthName)
177 strLength = KGlobal::locale()->monthName(date.month(), true).length();
178 break;
179 case 'B':// January (monthName)
180 strLength = KGlobal::locale()->monthName(date.month(), false).length();
181 break;
182 case 'y':// 04 (year short)
183 strLength = 2; //Ok
184 break;
185 case 'Y':// 2004 (year)
186 strLength = 4; //Ok
187 break;
188 default:
189 break;
190 }
191 space = begin - (repeat++ * 2);
192 // all select? then dayswitch
193 if( (mDateEdit->text().length() == mDateEdit->markedText().length() ) &&
194 ( (dateForm.at(begin + 1).latin1() == 'd') ||
195 (dateForm.at(begin + 1).latin1() == 'a') ||
196 (dateForm.at(begin + 1).latin1() == 'A') ) ) {
197 break;
198 }
199 // mDateEdit-StringPos == CursorPosition(cpos) then break and set date
200 if( ( (space + allStrLength) <= *cpos && *cpos <= (space + allStrLength + strLength) ) || *cpos < begin ) {
201 break;
202 }
203 allStrLength += strLength;
204 begin = dateForm.find("%", begin +1);
205 }
206
207 // set date
208 switch ( dateForm.at(begin + 1).latin1() ) {
209 case 'd':
210 case 'a':
211 case 'A':
212 if(key == Key_Up) {
213 setDate( date.addDays( 1 ) );
214 }
215 else if(key == Key_Down) {
216 setDate( date.addDays( -1 ) );
217 }
218 maxDay = readDate().day();
219 break;
220 case 'm':
221 case 'b':
222 case 'B':
223 if(key == Key_Up) {
224 int year = ((date.month()+1)>12)?date.year()+1:date.year();
225 int month = ((date.month()+1)>12)?1:date.month()+1;
226 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay;
227 setDate( QDate( year, month, day ) );
228 } else if(key == Key_Down) {
229 int year = ((date.month()-1)<1)?date.year()-1:date.year();
230 int month = ((date.month()-1)<1)?12:date.month()-1;
231 int day = (QDate(year,month,1).daysInMonth()<maxDay)?QDate(year,month,1).daysInMonth():maxDay;
232 setDate( QDate( year, month, day ) );
233 }
234 break;
235 case 'y':
236 case 'Y':
237 if(key == Key_Up) {
238 setDate( QDate( date.year() + 1, date.month() , date.day()) );
239 }
240 else if(key == Key_Down) {
241 setDate( QDate( date.year() - 1, date.month() , date.day()) );
242 }
243 break;
244/* default:
245 if(key == Key_Up) {
246 setDate( date.addDays( 1 ) );
247 } else if(key == Key_Down) {
248 setDate( date.addDays( -1 ) );
249 }
250 break;*/
251 }
252
253 date = readDate();
254 begin = dateForm.find("%");
255 int allSelectStrLength = 0;
256 int selectStrLength = 0;
257
258 // set selection do new date an set cursor at end of selection
259 for(int i = 0; i < repeat; i++){
260 switch ( dateForm.at(begin + 1).latin1() )
261 {
262 case 'd':// 16 (month day)
263 selectStrLength = 2; //Ok
264 break;
265 case 'm':// 01 (month)
266 selectStrLength = 2; //Ok
267 break;
268 case 'a':// Mon (Weekday short)
269 selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), true).length();
270 break;
271 case 'A':// Monday (Weekday)
272 selectStrLength = KGlobal::locale()->weekDayName(date.dayOfWeek(), false).length();
273 break;
274 case 'b':// Jan (monthName short)
275 selectStrLength = KGlobal::locale()->monthName(date.month(), true).length();
276 break;
277 case 'B':// January (monthName)
278 selectStrLength = KGlobal::locale()->monthName(date.month(), false).length();
279 break;
280 case 'y':// 04 (year short)
281 selectStrLength = 2; //Ok
282 break;
283 case 'Y':// 2004 (year)
284 selectStrLength = 4; //Ok
285 break;
286 default:
287 break;
288 }
289 space = begin - (i * 2);
290 allSelectStrLength += selectStrLength;
291 begin = dateForm.find("%", begin +1);
292 }
293 // set selection from begin of date
294 setSelect( space + allSelectStrLength - selectStrLength , selectStrLength);
295 *cpos = space + allSelectStrLength;
296 emit(dateChanged(date));
297
298 return;
299}
300
301void KDateEdit::setHandleInvalid(bool handleInvalid)
302{
303 mHandleInvalid = handleInvalid;
304}
305
306void KDateEdit::setEnabled(bool on)
307{
308 mDateEdit->setEnabled(on);
309 mDateButton->setEnabled(on);
310}
311
312QDate KDateEdit::date() const
313{
314 QDate date = readDate();
315
316 if (date.isValid() || mHandleInvalid) {
317 return date;
318 } else {
319 KNotifyClient::beep();
320 return QDate::currentDate();
321 }
322}
323
324void KDateEdit::keyPressEvent(QKeyEvent *e)
325{
326 QDate date = readDate();
327 int cpos = mDateEdit->cursorPosition();
328
329 switch(e->key())
330 {
331 case Key_Escape:
332 mDateEdit->deselect();
333 case Key_Tab:
334 QHBox::keyPressEvent(e);
335 break;
336 case Key_Up:
337 // when date invalid then set to currend and return
338 if(!date.isValid()) {
339 date = QDate::currentDate();
340 setDate(date);
341 mDateEdit->setCursorPosition(cpos);
342 emit(dateChanged(date));
343 QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
344 KMessageBox::information( 0, text );
345 return;
346 }
347 setDate(date, &cpos, Key_Up, dateFormShort);
348 break;
349 case Key_Down:
350 // when date invalid then set to current and return
351 if(!date.isValid()) {
352 date = QDate::currentDate();
353 setDate(date);
354 mDateEdit->setCursorPosition(cpos);
355 emit(dateChanged(date));
356 QString text = i18n( "You entered an invalid date!\n Date changed to current date." );
357 KMessageBox::information( 0, text );
358 return;
359 }
360 setDate(date, &cpos, Key_Down, dateFormShort);
361 break;
362 default:
363 QHBox::keyPressEvent(e);
364 break;
365 } // switch
366 mDateEdit->setCursorPosition(cpos);
367}
368
369void KDateEdit::setSelect( int from, int to )
370{
371// return;
372 mDateEdit->setSelection( from , to );
373}
374
375void KDateEdit::toggleDatePicker()
376{
377 if( mDateFrame->isVisible() ) {
378 mDateFrame->hide();
379 } else {
380 QPoint tmpPoint = mapToGlobal(mDateButton->geometry().bottomRight());
381 QSize datepickersize = mDatePicker->sizeHint();
382
383 if ( tmpPoint.x() < 7+datepickersize.width() ) tmpPoint.setX( 7+datepickersize.width() );
384
385 int h = QApplication::desktop()->height();
386
387 if ( tmpPoint.y() + datepickersize.height() > h ) tmpPoint.setY( h - datepickersize.height() );
388
389 mDateFrame->setGeometry(tmpPoint.x()-datepickersize.width()-7, tmpPoint.y(),
390 datepickersize.width()+2*mDateFrame->lineWidth(), datepickersize.height()+2*mDateFrame->lineWidth());
391
392 QDate date = readDate();
393 if(date.isValid()) {
394 mDatePicker->setDate(date);
395 } else {
396 mDatePicker->setDate(QDate::currentDate());
397 }
398 mDateFrame->show();
399 }
400}
401
402
403void KDateEdit::lineEnterPressed()
404{
405 QDate date = readDate();
406
407 if(date.isValid())
408 {
409 // Update the edit. This is needed if the user has entered a
410 // word rather than the actual date.
411 setDate(date);
412 emit(dateChanged(date));
413 emit returnPressed();
414 }
415 else
416 {
417 if ( withoutDp ) {
418 KNotifyClient::beep();
419 } else {
420 if ( !mDateEdit->text().isEmpty() ) {
421 mTextChanged = false;
422 QString text = i18n( "You entered an invalid date!\n Will use current date instead." );
423 if ( KMessageBox::warningContinueCancel( 0, text ) == KMessageBox::Continue ) {
424 setDate( QDate::currentDate() );
425 emit dateChanged( QDate::currentDate() );
426 }
427 }
428 }
429 }
430}
431
432bool KDateEdit::inputIsValid()
433{
434 return readDate().isValid();
435}
436
437QDate KDateEdit::readDate() const
438{
439 QString text = mDateEdit->text();
440 QDate date;
441
442 if (mKeywordMap.contains(text.lower()))
443 {
444 date = QDate::currentDate().addDays(mKeywordMap[text.lower()]);
445 }
446 else
447 {
448 date = KGlobal::locale()->readDate(text);
449 }
450
451 return date;
452}
453
454bool KDateEdit::eventFilter(QObject *, QEvent *e)
455{
456 // We only process the focus out event if the text has changed
457 // since we got focus
458 if ((e->type() == QEvent::FocusOut) && mTextChanged)
459 {
460 lineEnterPressed();
461 mTextChanged = false;
462 }
463 // switch dateFormShort by double klick with mouse
464 else if (e->type() == QEvent::MouseButtonDblClick)
465 {
466 dateFormShort = dateFormShort?false:true;
467 mDateEdit->setText(KGlobal::locale()->formatDate(readDate(),dateFormShort));
468 }
469 else if (e->type() == QEvent::FocusIn)
470 {
471 maxDay = readDate().day();
472 }
473
474 return false;
475}
476
477void KDateEdit::textChanged(const QString &)
478{
479 if(mHandleInvalid && mDateEdit->text().stripWhiteSpace().isEmpty()) {
480 QDate date; //invalid date
481 emit(dateChanged(date));
482 } else {
483 mTextChanged = true;
484 }
485 maxDay = readDate().day();
486}
diff --git a/libkdepim/kdateedit.h b/libkdepim/kdateedit.h
new file mode 100644
index 0000000..742d843
--- a/dev/null
+++ b/libkdepim/kdateedit.h
@@ -0,0 +1,140 @@
1/*
2 This file is part of libkdepim.
3
4 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable,
22 without including the source code for Qt in the source distribution.
23*/
24#ifndef KDATEEDIT_H
25#define KDATEEDIT_H
26
27#include <qhbox.h>
28#include <qvbox.h>
29#include <qdatetime.h>
30#include <qmap.h>
31
32class QLineEdit;
33class QPushButton;
34class QObject;
35class QEvent;
36class KDatePicker;
37class KDateValidator;
38
39/**
40* A date editing widget that consists of a line edit followed by
41* a small push button. The line edit contains the date in text form,
42* and the push button will display a 'popup' style date picker.
43*
44* This widget also supports advanced features like allowing the user
45* to type in the day name to get the date. The following keywords
46* are supported (in the native language): tomorrow, yesturday, today,
47* monday, tuesday, wednesday, thursday, friday, saturday, sunday.
48*
49* @author Cornelius Schumacher <schumacher@kde.org>
50* @author Mike Pilone <mpilone@slac.com>
51*/
52class KDateEdit : public QHBox
53{
54 Q_OBJECT
55 public:
56 KDateEdit(QWidget *parent=0, const char *name=0, bool withoutDP = false );
57 virtual ~KDateEdit();
58
59 /** @return True if the date in the text edit is valid,
60 * false otherwise. This will not modify the display of the date,
61 * but only check for validity.
62 */
63 bool inputIsValid();
64
65 /** @return The date entered. This will not
66 * modify the display of the date, but only return it.
67 */
68 QDate date() const;
69
70 /** @param handleInvalid If true the date edit accepts invalid dates
71 * and displays them as the empty ("") string. It also returns an invalid date.
72 * If false (default) invalid dates are not accepted and instead the date
73 * of today will be returned.
74 */
75 void setHandleInvalid(bool handleInvalid);
76
77 /** Checks for a focus out event. The display of the date is updated
78 * to display the proper date when the focus leaves.
79 */
80 virtual bool eventFilter(QObject *o, QEvent *e);
81
82 signals:
83 /** This signal is emitted whenever the user modifies the date. This
84 * may not get emitted until the user presses enter in the line edit or
85 * focus leaves the widget (ie: the user confirms their selection).
86 */
87 void dateChanged(QDate);
88 void returnPressed();
89 public slots:
90 /** Sets the date.
91 *
92 * @param date The new date to display. This date must be valid or
93 * it will not be displayed.
94 */
95 void setDate(QDate date);
96 // set Date with key_up key_down to relation of cursor Position
97 // and set selection from begin to end of single date
98 void setDate(QDate, int *cpos, const int, const bool);
99
100 /** Sets the date edit to be enabled or disabled (grayed out)
101 *
102 * @param on Enabled if true, disabled if false
103 */
104 void setEnabled(bool on);
105
106 protected slots:
107 void toggleDatePicker();
108 void lineEnterPressed();
109 void textChanged(const QString &);
110
111 private:
112 /** Reads the text from the line edit. If the text is a keyword, the
113 * word will be translated to a date. If the text is not a keyword, the
114 * text will be interpreted as a date.
115 */
116 QDate readDate() const;
117
118 /** Maps the text that the user can enter to the offset in days from
119 * today. For example, the text 'tomorrow' is mapped to +1.
120 */
121 QMap<QString, int> mKeywordMap;
122 bool mTextChanged;
123 bool mHandleInvalid;
124
125 QPushButton *mDateButton;
126 QLineEdit *mDateEdit;
127 KDatePicker *mDatePicker;
128 QVBox *mDateFrame;
129 int maxDay;
130 bool withoutDp;
131
132 protected:
133 virtual void keyPressEvent(QKeyEvent *qke);
134 void setSelect ( int, int );
135 bool dateFormShort;
136 char lengthMonthName;
137
138};
139
140#endif
diff --git a/libkdepim/kdateedit.moc b/libkdepim/kdateedit.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/kdateedit.moc
diff --git a/libkdepim/kdatepicker.cpp b/libkdepim/kdatepicker.cpp
new file mode 100644
index 0000000..6e5ec0f
--- a/dev/null
+++ b/libkdepim/kdatepicker.cpp
@@ -0,0 +1,472 @@
1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
4 (C) 1998-2001 Mirko Boehm (mirko@kde.org)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21#include "kdatepicker.h"
22#include <kglobal.h>
23#include <kapplication.h>
24#include <klocale.h>
25#include <kiconloader.h>
26#include <qframe.h>
27#include <qpainter.h>
28#include <qdialog.h>
29#include <qtoolbutton.h>
30#include <qfont.h>
31#include <qapplication.h>
32#include <qlineedit.h>
33#include <qvalidator.h>
34#include <kdebug.h>
35#include <knotifyclient.h>
36#include "kdatetbl.h"
37#include "kdateedit.h"
38#include "kdatepicker.moc"
39
40
41KDatePicker::KDatePicker(QWidget *parent, QDate dt, const char *name)
42 : QFrame(parent,name),
43 yearForward(new QToolButton(this)),
44 yearBackward(new QToolButton(this)),
45 monthForward(new QToolButton(this)),
46 monthBackward(new QToolButton(this)),
47 selectMonth(new QToolButton(this)),
48 selectYear(new QToolButton(this)),
49 //line(new QLineEdit(this)),
50 val(new KDateValidator(this))
51 //table(new KDateTable(this)),
52 //fontsize(1)
53{
54 // -----
55 int size = 12;
56 if ( QApplication::desktop()->width() >= 480 )
57 size = 18;
58 fontsize = size;
59 setFont ( QFont("helvetica",size) );
60 table = new KDateTable(this);
61 setFontSize(size);
62 //line->setValidator(val);
63 lineDate = new KDateEdit( this, "dateediipicker", true );
64 yearForward->setPixmap(SmallIcon("2rightarrowB"));
65 yearBackward->setPixmap(SmallIcon("2leftarrowB"));
66 monthForward->setPixmap(SmallIcon("1rightarrowB"));
67 monthBackward->setPixmap(SmallIcon("1leftarrowB"));
68
69 setDate(dt); // set button texts
70 connect(table, SIGNAL(dateChanged(QDate)), SLOT(dateChangedSlot(QDate)));
71 connect(table, SIGNAL(tableClicked()), SLOT(tableClickedSlot()));
72 connect(monthForward, SIGNAL(clicked()), SLOT(monthForwardClicked()));
73 connect(monthBackward, SIGNAL(clicked()), SLOT(monthBackwardClicked()));
74 connect(yearForward, SIGNAL(clicked()), SLOT(yearForwardClicked()));
75 connect(yearBackward, SIGNAL(clicked()), SLOT(yearBackwardClicked()));
76 connect(selectMonth, SIGNAL(clicked()), SLOT(selectMonthClicked()));
77 connect(selectYear, SIGNAL(clicked()), SLOT(selectYearClicked()));
78 //connect(line, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
79 connect(lineDate, SIGNAL(dateChanged(QDate)), SLOT(slotSetDate(QDate)));
80 connect(lineDate, SIGNAL(returnPressed()), SLOT(lineEnterPressed()));
81 table->setFocus();
82
83}
84
85KDatePicker::~KDatePicker()
86{
87}
88
89void
90KDatePicker::resizeEvent(QResizeEvent*)
91{
92 QWidget *buttons[] = {
93 yearBackward,
94 monthBackward,
95 selectMonth,
96 selectYear,
97 monthForward,
98 yearForward };
99 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
100 QSize sizes[NoOfButtons];
101 int buttonHeight=0;
102 int count;
103 int w;
104 int x=0;
105 // ----- calculate button row height:
106 for(count=0; count<NoOfButtons; ++count) {
107 int xS = buttons[count]->sizeHint().width();
108 int yS = buttons[count]->sizeHint().height();
109 sizes[count]=QSize ( xS+10, yS );
110 buttonHeight=QMAX(buttonHeight, sizes[count].height());
111 }
112 buttonHeight += 10;
113 // ----- calculate size of the month button:
114 w=0;
115 for(count=0; count<NoOfButtons; ++count) {
116 if(buttons[count]!=selectMonth)
117 {
118 w+=sizes[count].width();
119 } else {
120 x=count;
121 }
122 }
123 sizes[x].setWidth(width()-w); // stretch the month button
124 // ----- place the buttons:
125 x=0;
126 for(count=0; count<NoOfButtons; ++count)
127 {
128 w=sizes[count].width();
129 buttons[count]->setGeometry(x, 0, w, buttonHeight);
130 x+=w;
131 }
132 // ----- place the line edit for direct input:
133 sizes[0]=lineDate->sizeHint();
134 //line->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
135 lineDate->setGeometry(0, height()-sizes[0].height(), width(), sizes[0].height());
136 // ----- adjust the table:
137 table->setGeometry(0, buttonHeight, width(),
138 height()-buttonHeight-sizes[0].height());
139}
140
141void
142KDatePicker::dateChangedSlot(QDate date)
143{
144 lineDate->setDate( date );//(KGlobal::locale()->formatDate(date, true));
145 //line->setText(KGlobal::locale()->formatDate(date, true));
146 emit(dateChanged(date));
147}
148
149void
150KDatePicker::tableClickedSlot()
151{
152
153 emit(dateSelected(table->getDate()));
154 emit(tableClicked());
155}
156
157const QDate&
158KDatePicker::getDate() const
159{
160 return table->getDate();
161}
162
163const QDate &
164KDatePicker::date() const
165{
166 return table->getDate();
167}
168
169void KDatePicker::slotSetDate( QDate date )
170{
171
172 if(date.isValid()) {
173 QString temp;
174 // -----
175 table->setDate(date);
176 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
177 temp.setNum(date.year());
178 selectYear->setText(temp);
179 //line->setText(KGlobal::locale()->formatDate(date, true));
180 lineDate->setDate( date );
181 }
182
183}
184bool
185KDatePicker::setDate(const QDate& date)
186{
187 table->setFocus();
188 if(date.isValid()) {
189 QString temp;
190 // -----
191 table->setDate(date);
192 selectMonth->setText(KGlobal::locale()->monthName(date.month(), false));
193 temp.setNum(date.year());
194 selectYear->setText(temp);
195 //line->setText(KGlobal::locale()->formatDate(date, true));
196 lineDate->setDate( date );
197 return true;
198 } else {
199
200 return false;
201 }
202
203
204}
205
206void
207KDatePicker::monthForwardClicked()
208{
209 QDate temp=table->getDate();
210 int day=temp.day();
211 // -----
212 if(temp.month()==12) {
213 temp.setYMD(temp.year()+1, 1, 1);
214 } else {
215 temp.setYMD(temp.year(), temp.month()+1, 1);
216 }
217 if(temp.daysInMonth()<day) {
218 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
219 } else {
220 temp.setYMD(temp.year(), temp.month(), day);
221 }
222 // assert(temp.isValid());
223 setDate(temp);
224}
225
226void
227KDatePicker::monthBackwardClicked()
228{
229 QDate temp=table->getDate();
230 int day=temp.day();
231 // -----
232 if(temp.month()==1)
233 {
234 temp.setYMD(temp.year()-1, 12, 1);
235 } else {
236 temp.setYMD(temp.year(), temp.month()-1, 1);
237 }
238 if(temp.daysInMonth()<day)
239 {
240 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
241 } else {
242 temp.setYMD(temp.year(), temp.month(), day);
243 }
244 // assert(temp.isValid());
245 setDate(temp);
246}
247
248void
249KDatePicker::yearForwardClicked()
250{
251 QDate temp=table->getDate();
252 int day=temp.day();
253 // -----
254 temp.setYMD(temp.year()+1, temp.month(), 1);
255 if(temp.daysInMonth()<day)
256 {
257 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
258 } else {
259 temp.setYMD(temp.year(), temp.month(), day);
260 }
261 // assert(temp.isValid());
262 setDate(temp);
263}
264
265void
266KDatePicker::yearBackwardClicked()
267{
268 QDate temp=table->getDate();
269 int day=temp.day();
270 // -----
271 temp.setYMD(temp.year()-1, temp.month(), 1);
272 if(temp.daysInMonth()<day)
273 {
274 temp.setYMD(temp.year(), temp.month(), temp.daysInMonth());
275 } else {
276 temp.setYMD(temp.year(), temp.month(), day);
277 }
278 // assert(temp.isValid());
279 setDate(temp);
280}
281
282void
283KDatePicker::selectMonthClicked()
284{
285 int month;
286 KPopupFrame* popup = new KPopupFrame(this);
287 KDateInternalMonthPicker* picker = new KDateInternalMonthPicker(fontsize, popup);
288 // -----
289 picker->resize(picker->sizeHint());
290 popup->setMainWidget(picker);
291 picker->setFocus();
292 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
293 if(popup->exec(selectMonth->mapToGlobal(QPoint(0, selectMonth->height()))))
294 {
295 QDate date;
296 int day;
297 // -----
298 month=picker->getResult();
299 date=table->getDate();
300 day=date.day();
301 // ----- construct a valid date in this month:
302 date.setYMD(date.year(), month, 1);
303 date.setYMD(date.year(), month, QMIN(day, date.daysInMonth()));
304 // ----- set this month
305 setDate(date);
306 } else {
307 KNotifyClient::beep();
308 }
309 delete popup;
310}
311
312void
313KDatePicker::selectYearClicked()
314{
315 int year;
316 KPopupFrame* popup = new KPopupFrame(this);
317 KDateInternalYearSelector* picker = new KDateInternalYearSelector(fontsize, popup);
318 // -----
319 picker->resize(picker->sizeHint());
320 popup->setMainWidget(picker);
321 connect(picker, SIGNAL(closeMe(int)), popup, SLOT(close(int)));
322 picker->setFocus();
323 if(popup->exec(selectYear->mapToGlobal(QPoint(0, selectMonth->height()))))
324 {
325 QDate date;
326 int day;
327 // -----
328 year=picker->getYear();
329 date=table->getDate();
330 day=date.day();
331 // ----- construct a valid date in this month:
332 date.setYMD(year, date.month(), 1);
333 date.setYMD(year, date.month(), QMIN(day, date.daysInMonth()));
334 // ----- set this month
335 setDate(date);
336 } else {
337 KNotifyClient::beep();
338 }
339 delete popup;
340}
341
342void
343KDatePicker::setEnabled(bool enable)
344{
345 QWidget *widgets[]= {
346 yearForward, yearBackward, monthForward, monthBackward,
347 selectMonth, selectYear,
348 lineDate, table };
349 const int Size=sizeof(widgets)/sizeof(widgets[0]);
350 int count;
351 // -----
352 for(count=0; count<Size; ++count)
353 {
354 widgets[count]->setEnabled(enable);
355 }
356}
357
358void
359KDatePicker::lineEnterPressed()
360{
361 QDate temp;
362 // -----
363 temp = lineDate->date();
364 //if(val->date(line->text(), temp)==QValidator::Acceptable)
365 //{
366 emit(dateEntered(temp));
367 setDate(temp);
368 // } else {
369// KNotifyClient::beep();
370// }
371}
372
373QSize
374KDatePicker::sizeHint() const
375{
376 QSize tableSize=table->sizeHint();
377 QWidget *buttons[]={
378 yearBackward,
379 monthBackward,
380 selectMonth,
381 selectYear,
382 monthForward,
383 yearForward };
384 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
385 QSize sizes[NoOfButtons];
386 int cx=0, cy=0, count;
387 // ----- store the size hints:
388 for(count=0; count<NoOfButtons; ++count)
389 {
390 sizes[count]=buttons[count]->sizeHint();
391 if(buttons[count]==selectMonth)
392 {
393 cx+=maxMonthRect.width()+15;
394 } else {
395 cx+=sizes[count].width()+15;
396 }
397 cy=QMAX(sizes[count].height(), cy);
398 }
399 // ----- calculate width hint:
400 cx=QMAX(cx, tableSize.width()); // line edit ignored
401 if ( cx > QApplication::desktop()->width() -5 )
402 cx = QApplication::desktop()->width() -5;
403 // ----- calculate height hint:
404 cy+=tableSize.height()+lineDate->sizeHint().height();
405
406 return QSize(cx, cy);
407}
408
409void
410KDatePicker::setFontSize(int s)
411{
412 QWidget *buttons[]= {
413 // yearBackward,
414 // monthBackward,
415 selectMonth,
416 selectYear,
417 // monthForward,
418 // yearForward
419 };
420 const int NoOfButtons=sizeof(buttons)/sizeof(buttons[0]);
421 int count;
422 QFont font;
423 QRect r;
424 // -----
425 fontsize=s;
426 for(count=0; count<NoOfButtons; ++count)
427 {
428 font=buttons[count]->font();
429 font.setPointSize(s);
430 buttons[count]->setFont(font);
431 }
432 QFontMetrics metrics(selectMonth->fontMetrics());
433 for(int i=1; i <= 12; ++i)
434 { // maxMonthRect is used by sizeHint()
435 r=metrics.boundingRect(KGlobal::locale()->monthName(i, false));
436 maxMonthRect.setWidth(QMAX(r.width(), maxMonthRect.width()));
437 maxMonthRect.setHeight(QMAX(r.height(), maxMonthRect.height()));
438 }
439 table->setFontSize(s);
440}
441
442void KDatePicker::virtual_hook( int id, void* data )
443{ /*BASE::virtual_hook( id, data );*/ }
444
445void KDatePicker::keyPressEvent ( QKeyEvent * e )
446{
447 switch ( e->key() ) {
448 case Qt::Key_Right:
449 monthForwardClicked();
450 break;
451 case Qt::Key_Left:
452 monthBackwardClicked();
453 break;
454
455 case Qt::Key_Down:
456 yearForwardClicked();
457
458 break;
459
460 case Qt::Key_Up:
461 yearBackwardClicked();
462 break;
463
464 case Qt::Key_Return:
465 tableClickedSlot();
466 break;
467
468 default:
469 break;
470 }
471
472}
diff --git a/libkdepim/kdatepicker.h b/libkdepim/kdatepicker.h
new file mode 100644
index 0000000..6625357
--- a/dev/null
+++ b/libkdepim/kdatepicker.h
@@ -0,0 +1,181 @@
1/* -*- C++ -*-
2 This file is part of the KDE libraries
3 Copyright (C) 1997 Tim D. Gilman (tdgilman@best.org)
4 (C) 1998-2001 Mirko Boehm (mirko@kde.org)
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef MICROKDE_KDATEPICKER_H
21#define MICROKDE_KDATEPICKER_H
22#include <qdatetime.h>
23#include <qframe.h>
24#include <qevent.h>
25
26class QLineEdit;
27class QToolButton;
28class KDateValidator;
29class KDateTable;
30class KDateEdit;
31
32/**
33 * Provides a widget for calendar date input.
34 *
35 * Different from the
36 * previous versions, it now emits two types of signals, either
37 * @ref dateSelected() or @ref dateEntered() (see documentation for both
38 * signals).
39 *
40 * A line edit has been added in the newer versions to allow the user
41 * to select a date directly by entering numbers like 19990101
42 * or 990101.
43 *
44 * @image kdatepicker.png KDatePicker
45 *
46 * @version $Id$
47 * @author Tim Gilman, Mirko Boehm
48 *
49 * @short A date selection widget.
50 **/
51class KDatePicker: public QFrame
52{
53 Q_OBJECT
54public:
55 /** The usual constructor. The given date will be displayed
56 * initially.
57 **/
58 KDatePicker(QWidget *parent=0,
59 QDate=QDate::currentDate(),
60 const char *name=0);
61 /**
62 * The destructor.
63 **/
64 virtual ~KDatePicker();
65
66 /** The size hint for date pickers. The size hint recommends the
67 * minimum size of the widget so that all elements may be placed
68 * without clipping. This sometimes looks ugly, so when using the
69 * size hint, try adding 28 to each of the reported numbers of
70 * pixels.
71 **/
72 QSize sizeHint() const;
73
74 /**
75 * Sets the date.
76 *
77 * @returns @p false and does not change anything
78 * if the date given is invalid.
79 **/
80 bool setDate(const QDate&);
81
82 /**
83 * Returns the selected date.
84 * @deprecated
85 **/
86 const QDate& getDate() const;
87
88 /**
89 * @returns the selected date.
90 */
91 const QDate &date() const;
92
93 /**
94 * Enables or disables the widget.
95 **/
96 void setEnabled(bool);
97
98 /**
99 * Sets the font size of the widgets elements.
100 **/
101 void setFontSize(int);
102 /**
103 * Returns the font size of the widget elements.
104 */
105 int fontSize() const
106 { return fontsize; }
107protected:
108 /// the resize event
109 void resizeEvent(QResizeEvent*);
110 /// the year forward button
111 QToolButton *yearForward;
112 /// the year backward button
113 QToolButton *yearBackward;
114 /// the month forward button
115 QToolButton *monthForward;
116 /// the month backward button
117 QToolButton *monthBackward;
118 /// the button for selecting the month directly
119 QToolButton *selectMonth;
120 /// the button for selecting the year directly
121 QToolButton *selectYear;
122 /// the line edit to enter the date directly
123 //QLineEdit *line;
124 KDateEdit *lineDate;
125 /// the validator for the line edit:
126 KDateValidator *val;
127 /// the date table
128 KDateTable *table;
129 /// the size calculated during resize events
130 // QSize sizehint;
131 /// the widest month string in pixels:
132 QSize maxMonthRect;
133protected slots:
134 void dateChangedSlot(QDate);
135 void tableClickedSlot();
136 void monthForwardClicked();
137 void monthBackwardClicked();
138 void yearForwardClicked();
139 void yearBackwardClicked();
140 void selectMonthClicked();
141 void selectYearClicked();
142 void lineEnterPressed();
143 void slotSetDate(QDate);
144signals:
145 /** This signal is emitted each time the selected date is changed.
146 * Usually, this does not mean that the date has been entered,
147 * since the date also changes, for example, when another month is
148 * selected.
149 * @see dateSelected
150 */
151 void dateChanged(QDate);
152 /** This signal is emitted each time a day has been selected by
153 * clicking on the table (hitting a day in the current month). It
154 * has the same meaning as dateSelected() in older versions of
155 * KDatePicker.
156 */
157 void dateSelected(QDate);
158 /** This signal is emitted when enter is pressed and a VALID date
159 * has been entered before into the line edit. Connect to both
160 * dateEntered() and dateSelected() to receive all events where the
161 * user really enters a date.
162 */
163 void dateEntered(QDate);
164 /** This signal is emitted when the day has been selected by
165 * clicking on it in the table.
166 */
167 void tableClicked();
168
169private:
170 /// the font size for the widget
171 int fontsize;
172
173protected:
174 virtual void virtual_hook( int id, void* data );
175private:
176 class KDatePickerPrivate;
177 KDatePickerPrivate *d;
178 void keyPressEvent ( QKeyEvent * ) ;
179};
180
181#endif // KDATEPICKER_H
diff --git a/libkdepim/kdatepicker.moc b/libkdepim/kdatepicker.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/kdatepicker.moc
diff --git a/libkdepim/kdepim.pro.back b/libkdepim/kdepim.pro.back
new file mode 100644
index 0000000..4dfc301
--- a/dev/null
+++ b/libkdepim/kdepim.pro.back
@@ -0,0 +1,34 @@
1 TEMPLATE= lib
2 CONFIG = qt warn_on release
3TARGET = kdepim
4INCLUDEPATH += ../microkde ../qtcompat
5INCLUDEPATH += . ..
6LIBS += -lmicrokde
7OBJECTS_DIR = obj/$(PLATFORM)
8MOC_DIR = moc
9DESTDIR=$(QPEDIR)/lib
10
11INTERFACES = \
12
13HEADERS = \
14 categoryeditdialog.h \
15 categoryeditdialog_base.h \
16 categoryselectdialog.h \
17 categoryselectdialog_base.h \
18 kdateedit.h \
19 kinputdialog.h \
20 kpimprefs.h \
21 kprefs.h \
22 kprefsdialog.h \
23
24SOURCES = \
25 categoryeditdialog.cpp \
26 categoryeditdialog_base.cpp \
27 categoryselectdialog.cpp \
28 categoryselectdialog_base.cpp \
29 kdateedit.cpp \
30 kinputdialog.cpp \
31 kpimprefs.cpp \
32 kprefs.cpp \
33 kprefsdialog.cpp \
34
diff --git a/libkdepim/kincidenceformatter.cpp b/libkdepim/kincidenceformatter.cpp
new file mode 100644
index 0000000..4815519
--- a/dev/null
+++ b/libkdepim/kincidenceformatter.cpp
@@ -0,0 +1,326 @@
1#include "kincidenceformatter.h"
2#include <kstaticdeleter.h>
3#include <kglobal.h>
4#include <klocale.h>
5#ifndef KORG_NOKABC
6#include <kabc/stdaddressbook.h>
7#define size count
8#endif
9
10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0;
11static KStaticDeleter<KIncidenceFormatter> insd;
12
13QString KIncidenceFormatter::getFormattedText( Incidence * inc )
14{
15// #ifndef QT_NO_INPUTDIALOG
16// return QInputDialog::getItem( caption, label, items, current, editable );
17// #else
18// return QString::null;
19// #endif
20 mText = "";
21 if ( inc->type() == "Event" )
22 setEvent((Event *) inc );
23 else if ( inc->type() == "Todo" )
24 setTodo((Todo *) inc );
25 return mText;
26}
27
28KIncidenceFormatter* KIncidenceFormatter::instance()
29{
30 if (!mInstance) {
31 mInstance = insd.setObject(new KIncidenceFormatter());
32 }
33 return mInstance;
34}
35KIncidenceFormatter::~KIncidenceFormatter()
36{
37 if (mInstance == this)
38 mInstance = insd.setObject(0);
39 //qDebug("KIncidenceFormatter::~KIncidenceFormatter ");
40}
41KIncidenceFormatter::KIncidenceFormatter()
42{
43 mColorMode = 0;
44}
45void KIncidenceFormatter::setEvent(Event *event)
46{
47 int mode = 0;
48 mCurrentIncidence = event;
49 bool shortDate = true;
50 if ( mode == 0 ) {
51 addTag("h3",event->summary());
52 }
53 else {
54 if ( mColorMode == 1 ) {
55 mText +="<font color=\"#00A000\">";
56 }
57 if ( mColorMode == 2 ) {
58 mText +="<font color=\"#C00000\">";
59 }
60 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
61 if ( mode == 1 ) {
62 addTag("h2",i18n( "Local: " ) +event->summary());
63 } else {
64 addTag("h2",i18n( "Remote: " ) +event->summary());
65 }
66 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
67 if ( mColorMode )
68 mText += "</font>";
69 }
70 if (event->cancelled ()) {
71 mText +="<font color=\"#B00000\">";
72 addTag("i",i18n("This event has been cancelled!"));
73 mText.append("<br>");
74 mText += "</font>";
75 }
76 if (!event->location().isEmpty()) {
77 addTag("b",i18n("Location: "));
78 mText.append(event->location()+"<br>");
79 }
80 if (event->doesFloat()) {
81 if (event->isMultiDay()) {
82 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
83 .arg(event->dtStartDateStr(shortDate))
84 .arg(event->dtEndDateStr(shortDate)));
85 } else {
86 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
87 }
88 } else {
89 if (event->isMultiDay()) {
90 mText.append(i18n("<p><b>From:</b> %1</p> ")
91 .arg(event->dtStartStr( shortDate)));
92 mText.append(i18n("<p><b>To:</b> %1</p>")
93 .arg(event->dtEndStr(shortDate)));
94 } else {
95 mText.append(i18n("<p><b>On:</b> %1</p> ")
96 .arg(event->dtStartDateStr( shortDate )));
97 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
98 .arg(event->dtStartTimeStr())
99 .arg(event->dtEndTimeStr()));
100 }
101 }
102
103 if (event->recurrence()->doesRecur()) {
104
105 QString recurText = event->recurrence()->recurrenceText();
106 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
107 bool last;
108 QDate start = QDate::currentDate();
109 QDate next;
110 next = event->recurrence()->getPreviousDate( start , &last );
111 if ( !last ) {
112 next = event->recurrence()->getNextDate( start.addDays( - 1 ) );
113 addTag("p",i18n("Next recurrence is on: ")+ KGlobal::locale()->formatDate( next, shortDate ) );
114 //addTag("p", KGlobal::locale()->formatDate( next, shortDate ));
115 } else {
116 addTag("p",i18n("<b>Last recurrence was on:</b>") );
117 addTag("p", KGlobal::locale()->formatDate( next, shortDate ));
118 }
119 }
120
121
122 if (event->isAlarmEnabled()) {
123 Alarm *alarm =event->alarms().first() ;
124 QDateTime t = alarm->time();
125 int min = t.secsTo( event->dtStart() )/60;
126 QString s =i18n("(%1 min before)").arg( min );
127 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate ));
128 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
129 //addTag("p",s);
130 }
131
132 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
133 // mText.append(event->secrecyStr()+"<br>");
134 formatCategories(event);
135 if (!event->description().isEmpty()) {
136 addTag("p",i18n("<b>Details: </b>"));
137 addTag("p",event->description());
138 }
139
140
141 formatReadOnly(event);
142 formatAttendees(event);
143
144
145}
146
147void KIncidenceFormatter::setTodo(Todo *event )
148{
149 int mode = 0;
150 mCurrentIncidence = event;
151 bool shortDate = true;
152 if (mode == 0 )
153 addTag("h3",event->summary());
154 else {
155 if ( mColorMode == 1 ) {
156 mText +="<font color=\"#00A000\">";
157 }
158 if ( mColorMode == 2 ) {
159 mText +="<font color=\"#B00000\">";
160 }
161 if ( mode == 1 ) {
162 addTag("h2",i18n( "Local: " ) +event->summary());
163 } else {
164 addTag("h2",i18n( "Remote: " ) +event->summary());
165 }
166 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
167 if ( mColorMode )
168 mText += "</font>";
169 }
170 if (event->cancelled ()) {
171 mText +="<font color=\"#B00000\">";
172 addTag("i",i18n("This todo has been cancelled!"));
173 mText.append("<br>");
174 mText += "</font>";
175 }
176
177 if (!event->location().isEmpty()) {
178 addTag("b",i18n("Location: "));
179 mText.append(event->location()+"<br>");
180 }
181 if (event->hasDueDate()) {
182 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate)));
183 }
184 mText.append(i18n("<p><b>Priority:</b> %2</p>")
185 .arg(QString::number(event->priority())));
186
187 mText.append(i18n("<p><i>%1 % completed</i></p>")
188 .arg(event->percentComplete()));
189 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
190 formatCategories(event);
191 if (!event->description().isEmpty()) {
192 addTag("p",i18n("<b>Details: </b>"));
193 addTag("p",event->description());
194 }
195
196
197
198 formatReadOnly(event);
199 formatAttendees(event);
200
201}
202
203void KIncidenceFormatter::setJournal(Journal* )
204{
205
206}
207
208void KIncidenceFormatter::formatCategories(Incidence *event)
209{
210 if (!event->categoriesStr().isEmpty()) {
211 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() );
212 //mText.append(event->categoriesStr());
213 }
214}
215void KIncidenceFormatter::addTag(const QString & tag,const QString & text)
216{
217 int number=text.contains("\n");
218 QString str = "<" + tag + ">";
219 QString tmpText=text;
220 QString tmpStr=str;
221 if(number !=-1)
222 {
223 if (number > 0) {
224 int pos=0;
225 QString tmp;
226 for(int i=0;i<=number;i++) {
227 pos=tmpText.find("\n");
228 tmp=tmpText.left(pos);
229 tmpText=tmpText.right(tmpText.length()-pos-1);
230 tmpStr+=tmp+"<br>";
231 }
232 }
233 else tmpStr += tmpText;
234 tmpStr+="</" + tag + ">";
235 mText.append(tmpStr);
236 }
237 else
238 {
239 str += text + "</" + tag + ">";
240 mText.append(str);
241 }
242}
243
244void KIncidenceFormatter::formatAttendees(Incidence *event)
245{
246 QPtrList<Attendee> attendees = event->attendees();
247 if (attendees.count()) {
248 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
249 addTag("h3",i18n("Organizer"));
250 mText.append("<ul><li>");
251#ifndef KORG_NOKABC
252
253 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
254 KABC::Addressee::List addressList;
255 addressList = add_book->findByEmail(event->organizer());
256 KABC::Addressee o = addressList.first();
257 if (!o.isEmpty() && addressList.size()<2) {
258 mText += "<a href=\"uid:" + o.uid() + "\">";
259 mText += o.formattedName();
260 mText += "</a>\n";
261 } else {
262 mText.append(event->organizer());
263 }
264#else
265 mText.append(event->organizer());
266#endif
267 if (iconPath) {
268 mText += " <a href=\"mailto:" + event->organizer() + "\">";
269 mText += "<IMG src=\"" + iconPath + "\">";
270 mText += "</a>\n";
271 }
272 mText.append("</li></ul>");
273
274 addTag("h3",i18n("Attendees"));
275 Attendee *a;
276 mText.append("<ul>");
277 for(a=attendees.first();a;a=attendees.next()) {
278#ifndef KORG_NOKABC
279 if (a->name().isEmpty()) {
280 addressList = add_book->findByEmail(a->email());
281 KABC::Addressee o = addressList.first();
282 if (!o.isEmpty() && addressList.size()<2) {
283 mText += "<a href=\"uid:" + o.uid() + "\">";
284 mText += o.formattedName();
285 mText += "</a>\n";
286 } else {
287 mText += "<li>";
288 mText.append(a->email());
289 mText += "\n";
290 }
291 } else {
292 mText += "<li><a href=\"uid:" + a->uid() + "\">";
293 if (!a->name().isEmpty()) mText += a->name();
294 else mText += a->email();
295 mText += "</a>\n";
296 }
297#else
298 //qDebug("nokabc ");
299 mText += "<li><a href=\"uid:" + a->uid() + "\">";
300 if (!a->name().isEmpty()) mText += a->name();
301 else mText += a->email();
302 mText += "</a>\n";
303#endif
304
305 if (!a->email().isEmpty()) {
306 if (iconPath) {
307 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
308 mText += "<IMG src=\"" + iconPath + "\">";
309 mText += "</a>\n";
310 }
311 }
312 if (a->status() != Attendee::NeedsAction )
313 mText +="[" + a->statusStr() + "] ";
314 if (a->role() == Attendee::Chair )
315 mText +="(" + a->roleStr().left(1) + ".)";
316 }
317 mText.append("</li></ul>");
318 }
319}
320
321void KIncidenceFormatter::formatReadOnly(Incidence *event)
322{
323 if (event->isReadOnly()) {
324 addTag("p","<em>(" + i18n("read-only") + ")</em>");
325 }
326}
diff --git a/libkdepim/kincidenceformatter.h b/libkdepim/kincidenceformatter.h
new file mode 100644
index 0000000..8fe259a
--- a/dev/null
+++ b/libkdepim/kincidenceformatter.h
@@ -0,0 +1,42 @@
1#ifndef KINCIDENCENFORMATTER_H
2#define KINCIDENCENFORMATTER_H
3
4#include <qstring.h>
5#include <qobject.h>
6
7#include "libkcal/incidence.h"
8#include "libkcal/event.h"
9#include "libkcal/todo.h"
10#include "libkcal/journal.h"
11
12using namespace KCal;
13
14class KIncidenceFormatter : public QObject
15{
16 public:
17 static KIncidenceFormatter* instance();
18 KIncidenceFormatter();
19 ~KIncidenceFormatter();
20 QString getFormattedText( Incidence * inc );
21
22 void setEvent(Event *event);
23 void setTodo(Todo *event );
24 void setJournal(Journal* );
25
26 protected:
27 int mColorMode;
28 void addTag(const QString & tag,const QString & text);
29
30 void formatCategories(Incidence *event);
31 void formatAttendees(Incidence *event);
32 void formatReadOnly(Incidence *event);
33
34 private:
35 bool mSyncMode;
36
37 QString mText;
38 Incidence* mCurrentIncidence;
39 static KIncidenceFormatter* mInstance;
40};
41
42#endif
diff --git a/libkdepim/kinputdialog.cpp b/libkdepim/kinputdialog.cpp
new file mode 100644
index 0000000..0c31ca9
--- a/dev/null
+++ b/libkdepim/kinputdialog.cpp
@@ -0,0 +1,14 @@
1#include "kinputdialog.h"
2
3#include <qinputdialog.h>
4
5QString KInputDialog::getItem( const QString &caption, const QString &label,
6 const QStringList &items, int current,
7 bool editable )
8{
9#ifndef QT_NO_INPUTDIALOG
10 return QInputDialog::getItem( caption, label, items, current, editable );
11#else
12 return QString::null;
13#endif
14}
diff --git a/libkdepim/kinputdialog.h b/libkdepim/kinputdialog.h
new file mode 100644
index 0000000..0072391
--- a/dev/null
+++ b/libkdepim/kinputdialog.h
@@ -0,0 +1,15 @@
1#ifndef KINPUTDIALOG_H
2#define KINPUTDIALOG_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6
7class KInputDialog
8{
9 public:
10 static QString getItem( const QString &caption, const QString &label,
11 const QStringList &items, int current,
12 bool editable );
13};
14
15#endif
diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp
new file mode 100644
index 0000000..ce4c540
--- a/dev/null
+++ b/libkdepim/kpimprefs.cpp
@@ -0,0 +1,59 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24#include <kglobal.h>
25#include <kconfig.h>
26#include <klocale.h>
27#include <kdebug.h>
28
29#include "kpimprefs.h"
30
31KPimPrefs::KPimPrefs( const QString &name ) :
32 KPrefs( name )
33{
34}
35
36KPimPrefs::~KPimPrefs()
37{
38}
39
40void KPimPrefs::usrSetDefaults()
41{
42 setCategoryDefaults();
43}
44
45void KPimPrefs::usrReadConfig()
46{
47 kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl;
48
49 config()->setGroup("General");
50 mCustomCategories = config()->readListEntry("Custom Categories");
51 if (mCustomCategories.isEmpty()) setCategoryDefaults();
52}
53
54
55void KPimPrefs::usrWriteConfig()
56{
57 config()->setGroup("General");
58 config()->writeEntry("Custom Categories",mCustomCategories);
59}
diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h
new file mode 100644
index 0000000..05a564c
--- a/dev/null
+++ b/libkdepim/kpimprefs.h
@@ -0,0 +1,53 @@
1/*
2 This file is part of libkdepim.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#ifndef KPIMPREFS_H
24#define KPIMPREFS_H
25
26#include <qstringlist.h>
27
28#include "kprefs.h"
29
30class KPimPrefs : public KPrefs
31{
32 public:
33 KPimPrefs( const QString &name = QString::null );
34
35 virtual ~KPimPrefs();
36
37 /** Set preferences to default values */
38 void usrSetDefaults();
39
40 /** Read preferences from config file */
41 void usrReadConfig();
42
43 /** Write preferences to config file */
44 void usrWriteConfig();
45
46 public:
47 QStringList mCustomCategories;
48
49 protected:
50 virtual void setCategoryDefaults() = 0;
51};
52
53#endif
diff --git a/libkdepim/kprefs.cpp b/libkdepim/kprefs.cpp
new file mode 100644
index 0000000..f5e5e5a
--- a/dev/null
+++ b/libkdepim/kprefs.cpp
@@ -0,0 +1,463 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21// $Id$
22
23#include <qcolor.h>
24
25#include <kconfig.h>
26#include <kstandarddirs.h>
27#include <kglobal.h>
28#include <kdebug.h>
29
30#include "kprefs.h"
31
32class KPrefsItemBool : public KPrefsItem {
33 public:
34 KPrefsItemBool(const QString &group,const QString &name,bool *,bool defaultValue=true);
35 virtual ~KPrefsItemBool() {}
36
37 void setDefault();
38 void readConfig(KConfig *);
39 void writeConfig(KConfig *);
40
41 private:
42 bool *mReference;
43 bool mDefault;
44};
45
46class KPrefsItemInt : public KPrefsItem {
47 public:
48 KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0);
49 virtual ~KPrefsItemInt() {}
50
51 void setDefault();
52 void readConfig(KConfig *);
53 void writeConfig(KConfig *);
54
55 private:
56 int *mReference;
57 int mDefault;
58};
59
60
61class KPrefsItemColor : public KPrefsItem {
62 public:
63 KPrefsItemColor(const QString &group,const QString &name,QColor *,
64 const QColor &defaultValue=QColor(128,128,128));
65 virtual ~KPrefsItemColor() {}
66
67 void setDefault();
68 void readConfig(KConfig *);
69 void writeConfig(KConfig *);
70
71 private:
72 QColor *mReference;
73 QColor mDefault;
74};
75
76
77class KPrefsItemFont : public KPrefsItem {
78 public:
79 KPrefsItemFont(const QString &group,const QString &name,QFont *,
80 const QFont &defaultValue=QFont("helvetica",12));
81 virtual ~KPrefsItemFont() {}
82
83 void setDefault();
84 void readConfig(KConfig *);
85 void writeConfig(KConfig *);
86
87 private:
88 QFont *mReference;
89 QFont mDefault;
90};
91
92
93class KPrefsItemString : public KPrefsItem {
94 public:
95 KPrefsItemString(const QString &group,const QString &name,QString *,
96 const QString &defaultValue="", bool isPassword=false);
97 virtual ~KPrefsItemString() {}
98
99 void setDefault();
100 void readConfig(KConfig *);
101 void writeConfig(KConfig *);
102
103 private:
104 QString *mReference;
105 QString mDefault;
106 bool mPassword;
107};
108
109
110class KPrefsItemStringList : public KPrefsItem {
111 public:
112 KPrefsItemStringList(const QString &group,const QString &name,QStringList *,
113 const QStringList &defaultValue=QStringList());
114 virtual ~KPrefsItemStringList() {}
115
116 void setDefault();
117 void readConfig(KConfig *);
118 void writeConfig(KConfig *);
119
120 private:
121 QStringList *mReference;
122 QStringList mDefault;
123};
124
125
126class KPrefsItemIntList : public KPrefsItem {
127 public:
128 KPrefsItemIntList(const QString &group,const QString &name,QValueList<int> *,
129 const QValueList<int> &defaultValue=QValueList<int>());
130 virtual ~KPrefsItemIntList() {}
131
132 void setDefault();
133 void readConfig(KConfig *);
134 void writeConfig(KConfig *);
135
136 private:
137 QValueList<int> *mReference;
138 QValueList<int> mDefault;
139};
140
141
142KPrefsItemBool::KPrefsItemBool(const QString &group,const QString &name,
143 bool *reference,bool defaultValue) :
144 KPrefsItem(group,name)
145{
146 mReference = reference;
147 mDefault = defaultValue;
148}
149
150void KPrefsItemBool::setDefault()
151{
152 *mReference = mDefault;
153}
154
155void KPrefsItemBool::writeConfig(KConfig *config)
156{
157 config->setGroup(mGroup);
158 config->writeEntry(mName,*mReference);
159}
160
161
162void KPrefsItemBool::readConfig(KConfig *config)
163{
164 config->setGroup(mGroup);
165 *mReference = config->readBoolEntry(mName,mDefault);
166}
167
168
169KPrefsItemInt::KPrefsItemInt(const QString &group,const QString &name,
170 int *reference,int defaultValue) :
171 KPrefsItem(group,name)
172{
173 mReference = reference;
174 mDefault = defaultValue;
175}
176
177void KPrefsItemInt::setDefault()
178{
179 *mReference = mDefault;
180}
181
182void KPrefsItemInt::writeConfig(KConfig *config)
183{
184 config->setGroup(mGroup);
185 config->writeEntry(mName,*mReference);
186}
187
188void KPrefsItemInt::readConfig(KConfig *config)
189{
190 config->setGroup(mGroup);
191 *mReference = config->readNumEntry(mName,mDefault);
192}
193
194
195KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name,
196 QColor *reference,const QColor &defaultValue) :
197 KPrefsItem(group,name)
198{
199 mReference = reference;
200 mDefault = defaultValue;
201}
202
203void KPrefsItemColor::setDefault()
204{
205 *mReference = mDefault;
206}
207
208void KPrefsItemColor::writeConfig(KConfig *config)
209{
210 config->setGroup(mGroup);
211 config->writeEntry(mName,*mReference);
212}
213
214void KPrefsItemColor::readConfig(KConfig *config)
215{
216 config->setGroup(mGroup);
217 *mReference = config->readColorEntry(mName,&mDefault);
218
219}
220
221
222KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name,
223 QFont *reference,const QFont &defaultValue) :
224 KPrefsItem(group,name)
225{
226 mReference = reference;
227 mDefault = defaultValue;
228}
229
230void KPrefsItemFont::setDefault()
231{
232 *mReference = mDefault;
233}
234
235void KPrefsItemFont::writeConfig(KConfig *config)
236{
237 config->setGroup(mGroup);
238 config->writeEntry(mName,*mReference);
239}
240
241void KPrefsItemFont::readConfig(KConfig *config)
242{
243 config->setGroup(mGroup);
244 *mReference = config->readFontEntry(mName,&mDefault);
245}
246
247
248QString endecryptStr( const QString &aStr )
249{
250 QString result;
251 uint i;
252 for ( i = 0; i < aStr.length(); i++)
253 result += (aStr.at(i).unicode() < 0x20) ?
254 aStr.at(i) :
255 QChar(0x1001F - aStr.at(i).unicode());
256 return result;
257}
258
259
260KPrefsItemString::KPrefsItemString(const QString &group,const QString &name,
261 QString *reference,const QString &defaultValue,
262 bool isPassword) :
263 KPrefsItem(group,name)
264{
265 mReference = reference;
266 mDefault = defaultValue;
267 mPassword = isPassword;
268}
269
270void KPrefsItemString::setDefault()
271{
272 *mReference = mDefault;
273}
274
275void KPrefsItemString::writeConfig(KConfig *config)
276{
277 config->setGroup(mGroup);
278 if ( mPassword )
279 config->writeEntry(mName, endecryptStr( *mReference ) );
280 else
281 config->writeEntry(mName,*mReference);
282}
283
284void KPrefsItemString::readConfig(KConfig *config)
285{
286 config->setGroup(mGroup);
287
288 QString value;
289 if ( mPassword ) {
290 value = config->readEntry( mName, endecryptStr( mDefault ) );
291 *mReference = endecryptStr( value );
292 } else {
293 *mReference = config->readEntry( mName, mDefault );
294 }
295}
296
297
298KPrefsItemStringList::KPrefsItemStringList(const QString &group,const QString &name,
299 QStringList *reference,const QStringList &defaultValue) :
300 KPrefsItem(group,name)
301{
302 mReference = reference;
303 mDefault = defaultValue;
304}
305
306void KPrefsItemStringList::setDefault()
307{
308 *mReference = mDefault;
309}
310
311void KPrefsItemStringList::writeConfig(KConfig *config)
312{
313 config->setGroup(mGroup);
314 config->writeEntry(mName,*mReference);
315}
316
317void KPrefsItemStringList::readConfig(KConfig *config)
318{
319 config->setGroup(mGroup);
320 *mReference = config->readListEntry(mName);
321}
322
323
324KPrefsItemIntList::KPrefsItemIntList(const QString &group,const QString &name,
325 QValueList<int> *reference,const QValueList<int> &defaultValue) :
326 KPrefsItem(group,name)
327{
328 mReference = reference;
329 mDefault = defaultValue;
330}
331
332void KPrefsItemIntList::setDefault()
333{
334 *mReference = mDefault;
335}
336
337void KPrefsItemIntList::writeConfig(KConfig *config)
338{
339 config->setGroup(mGroup);
340 config->writeEntry(mName,*mReference);
341}
342
343void KPrefsItemIntList::readConfig(KConfig *config)
344{
345 config->setGroup(mGroup);
346 *mReference = config->readIntListEntry(mName);
347}
348
349
350QString *KPrefs::mCurrentGroup = 0;
351
352KPrefs::KPrefs(const QString &configname)
353{
354 if (!configname.isEmpty()) {
355 //qDebug("KPrefs::KPrefs %s",configname.latin1() );
356 mConfig = new KConfig(locateLocal("config",configname));
357 } else {
358 mConfig = KGlobal::config();
359 }
360
361 mItems.setAutoDelete(true);
362
363 // Set default group
364 if (mCurrentGroup == 0) mCurrentGroup = new QString("No Group");
365}
366
367KPrefs::~KPrefs()
368{
369 if (mConfig != KGlobal::config()) {
370 delete mConfig;
371 }
372}
373
374void KPrefs::setCurrentGroup(const QString &group)
375{
376 if (mCurrentGroup) delete mCurrentGroup;
377 mCurrentGroup = new QString(group);
378}
379
380KConfig *KPrefs::config() const
381{
382 return mConfig;
383}
384
385void KPrefs::setDefaults()
386{
387 KPrefsItem *item;
388 for(item = mItems.first();item;item = mItems.next()) {
389 item->setDefault();
390 }
391
392 usrSetDefaults();
393}
394
395void KPrefs::readConfig()
396{
397 KPrefsItem *item;
398 for(item = mItems.first();item;item = mItems.next()) {
399 item->readConfig(mConfig);
400 }
401
402 usrReadConfig();
403}
404
405void KPrefs::writeConfig()
406{
407 KPrefsItem *item;
408 for(item = mItems.first();item;item = mItems.next()) {
409 item->writeConfig(mConfig);
410 }
411
412 usrWriteConfig();
413
414 mConfig->sync();
415}
416
417
418void KPrefs::addItem(KPrefsItem *item)
419{
420 mItems.append(item);
421}
422
423void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue)
424{
425 addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue));
426}
427
428void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue)
429{
430 addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue));
431}
432
433void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue)
434{
435 addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue));
436}
437
438void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue)
439{
440 addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue));
441}
442
443void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue)
444{
445 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false));
446}
447
448void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue)
449{
450 addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true));
451}
452
453void KPrefs::addItemStringList(const QString &key,QStringList *reference,
454 const QStringList &defaultValue)
455{
456 addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue));
457}
458
459void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference,
460 const QValueList<int> &defaultValue)
461{
462 addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue));
463}
diff --git a/libkdepim/kprefs.h b/libkdepim/kprefs.h
new file mode 100644
index 0000000..7014bb8
--- a/dev/null
+++ b/libkdepim/kprefs.h
@@ -0,0 +1,301 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef _KPREFS_H
21#define _KPREFS_H
22// $Id$
23
24#include <qptrlist.h>
25#include <qcolor.h>
26#include <qfont.h>
27#include <qstringlist.h>
28
29class KConfig;
30
31/**
32 @short Class for storing a preferences setting
33 @author Cornelius Schumacher
34 @see KPref
35
36 This class represents one preferences setting as used by @ref KPrefs.
37 Subclasses of KPrefsItem implement storage functions for a certain type of
38 setting. Normally you don't have to use this class directly. Use the special
39 addItem() functions of KPrefs instead. If you subclass this class you will
40 have to register instances with the function KPrefs::addItem().
41*/
42class KPrefsItem {
43 public:
44 /**
45 Constructor.
46
47 @param group Config file group.
48 @param name Config file key.
49 */
50 KPrefsItem(const QString &group,const QString &name) :
51 mGroup(group),mName(name) {}
52 /**
53 Destructor.
54 */
55 virtual ~KPrefsItem() {}
56
57 /**
58 This function is called by @ref KPrefs to set this setting to its default
59 value.
60 */
61 virtual void setDefault() = 0;
62 /**
63 This function is called by @ref KPrefs to read the value for this setting
64 from a config file.
65 value.
66 */
67 virtual void readConfig(KConfig *) = 0;
68 /**
69 This function is called by @ref KPrefs to write the value of this setting
70 to a config file.
71 */
72 virtual void writeConfig(KConfig *) = 0;
73
74 protected:
75 QString mGroup;
76 QString mName;
77};
78
79/**
80 @short Class for handling preferences settings for an application.
81 @author Cornelius Schumacher
82 @see KPrefsItem
83
84 This class provides an interface to preferences settings. Preferences items
85 can be registered by the addItem() function corresponding to the data type of
86 the seetting. KPrefs then handles reading and writing of config files and
87 setting of default values.
88
89 Normally you will subclass KPrefs, add data members for the preferences
90 settings and register the members in the constructor of the subclass.
91
92 Example:
93 <pre>
94 class MyPrefs : public KPrefs {
95 public:
96 MyPrefs()
97 {
98 setCurrentGroup("MyGroup");
99 addItemBool("MySetting1",&mMyBool,false);
100 addItemColor("MySetting2",&mMyColor,QColor(1,2,3));
101
102 setCurrentGroup("MyOtherGroup");
103 addItemFont("MySetting3",&mMyFont,QFont("helvetica",12));
104 }
105
106 bool mMyBool;
107 QColor mMyColor;
108 QFont mMyFont;
109 }
110 </pre>
111
112 It might be convenient in many cases to make this subclass of KPrefs a
113 singleton for global access from all over the application without passing
114 references to the KPrefs object around.
115
116 You can set all values to default values by calling @ref setDefaults(), write
117 the data to the configuration file by calling @ref writeConfig() and read the
118 data from the configuration file by calling @ref readConfig().
119
120 If you have items, which are not covered by the existing addItem() functions
121 you can add customized code for reading, writing and default setting by
122 implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and
123 @ref usrWriteConfig().
124
125 Internally preferences settings are stored in instances of subclasses of
126 @ref KPrefsItem. You can also add KPrefsItem subclasses for your own types
127 and call the generic @ref addItem() to register them.
128*/
129
130class KPrefs {
131 public:
132 /**
133 Constructor.
134
135 @param configname name of config file. If no name is given, the default
136 config file as returned by kapp()->config() is used.
137 */
138 KPrefs(const QString &configname=QString::null);
139 /**
140 Destructor
141 */
142 virtual ~KPrefs();
143
144 /**
145 Set preferences to default values. All registered items are set to their
146 default values.
147 */
148 void setDefaults();
149
150 /**
151 Read preferences from config file. All registered items are set to the
152 values read from disk.
153 */
154 void readConfig();
155
156 /**
157 Write preferences to config file. The values of all registered items are
158 written to disk.
159 */
160 void writeConfig();
161
162 /**
163 Set the config file group for subsequent addItem() calls. It is valid
164 until setCurrentGroup() is called with a new argument. Call this before
165 you add any items. The default value is "No Group".
166 */
167 static void setCurrentGroup(const QString &group);
168
169 /**
170 Register a custom @ref KPrefsItem.
171 */
172 void addItem(KPrefsItem *);
173
174 /**
175 Register an item of type bool.
176
177 @param key Key used in config file.
178 @param reference Pointer to the variable, which is set by readConfig()
179 and setDefaults() calls and read by writeConfig() calls.
180 @param defaultValue Default value, which is used by setDefaults() and
181 when the config file does not yet contain the key of
182 this item.
183 */
184 void addItemBool(const QString &key,bool *reference,
185 bool defaultValue=false);
186 /**
187 Register an item of type int.
188
189 @param key Key used in config file.
190 @param reference Pointer to the variable, which is set by readConfig()
191 and setDefaults() calls and read by writeConfig() calls.
192 @param defaultValue Default value, which is used by setDefaults() and
193 when the config file does not yet contain the key of
194 this item.
195 */
196 void addItemInt(const QString &key,int *reference,
197 int defaultValue=0);
198 /**
199 Register an item of type QColor.
200
201 @param key Key used in config file.
202 @param reference Pointer to the variable, which is set by readConfig()
203 and setDefaults() calls and read by writeConfig() calls.
204 @param defaultValue Default value, which is used by setDefaults() and
205 when the config file does not yet contain the key of
206 this item.
207 */
208 void addItemColor(const QString &key,QColor *reference,
209 const QColor &defaultValue=QColor(128,128,128));
210 /**
211 Register an item of type QFont.
212
213 @param key Key used in config file.
214 @param reference Pointer to the variable, which is set by readConfig()
215 and setDefaults() calls and read by writeConfig() calls.
216 @param defaultValue Default value, which is used by setDefaults() and
217 when the config file does not yet contain the key of
218 this item.
219 */
220 void addItemFont(const QString &key,QFont *reference,
221 const QFont &defaultValue=QFont("helvetica",12));
222 /**
223 Register an item of type QString.
224
225 @param key Key used in config file.
226 @param reference Pointer to the variable, which is set by readConfig()
227 and setDefaults() calls and read by writeConfig() calls.
228 @param defaultValue Default value, which is used by setDefaults() and
229 when the config file does not yet contain the key of
230 this item.
231 */
232 void addItemString(const QString &key,QString *reference,
233 const QString &defaultValue="");
234 /**
235 Register a password item of type QString. The string value is written
236 encrypted to the config file. Note that the current encryption scheme
237 is very weak.
238
239 @param key Key used in config file.
240 @param reference Pointer to the variable, which is set by readConfig()
241 and setDefaults() calls and read by writeConfig() calls.
242 @param defaultValue Default value, which is used by setDefaults() and
243 when the config file does not yet contain the key of
244 this item.
245 */
246 void addItemPassword(const QString &key,QString *reference,
247 const QString &defaultValue="");
248 /**
249 Register an item of type QStringList.
250
251 @param key Key used in config file.
252 @param reference Pointer to the variable, which is set by readConfig()
253 and setDefaults() calls and read by writeConfig() calls.
254 @param defaultValue Default value, which is used by setDefaults() and
255 when the config file does not yet contain the key of
256 this item.
257 */
258 void addItemStringList(const QString &key,QStringList *reference,
259 const QStringList &defaultValue=QStringList());
260
261 /**
262 Register an item of type QValueList<int>.
263
264 @param key Key used in config file.
265 @param reference Pointer to the variable, which is set by readConfig()
266 and setDefaults() calls and read by writeConfig() calls.
267 @param defaultValue Default value, which is used by setDefaults() and
268 when the config file does not yet contain the key of
269 this item.
270 */
271 void addItemIntList(const QString &key,QValueList<int> *reference,
272 const QValueList<int> &defaultValue=QValueList<int>());
273
274 protected:
275 /**
276 Implemented by subclasses that use special defaults.
277 */
278 virtual void usrSetDefaults() {};
279 /**
280 Implemented by subclasses that read special config values.
281 */
282 virtual void usrReadConfig() {};
283 /**
284 Implemented by subclasses that write special config values.
285 */
286 virtual void usrWriteConfig() {};
287
288 /**
289 Return the @ref KConfig object used for reading and writing the settings.
290 */
291 KConfig *config() const;
292
293 private:
294 static QString *mCurrentGroup;
295
296 KConfig *mConfig; // pointer to KConfig object
297
298 QPtrList<KPrefsItem> mItems;
299};
300
301#endif
diff --git a/libkdepim/kprefsdialog.cpp b/libkdepim/kprefsdialog.cpp
new file mode 100644
index 0000000..3a39ea9
--- a/dev/null
+++ b/libkdepim/kprefsdialog.cpp
@@ -0,0 +1,410 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24// $Id$
25
26#include <qlayout.h>
27#include <qlabel.h>
28#include <qgroupbox.h>
29#include <qbuttongroup.h>
30#include <qlineedit.h>
31#include <qfont.h>
32#include <qslider.h>
33#include <qfile.h>
34#include <qtextstream.h>
35#include <qvbox.h>
36#include <qhbox.h>
37#include <qspinbox.h>
38#include <qdatetime.h>
39#include <qframe.h>
40#include <qcombobox.h>
41#include <qcheckbox.h>
42#include <qradiobutton.h>
43#include <qpushbutton.h>
44#include <qapplication.h>
45
46#include <kcolorbutton.h>
47#include <kdebug.h>
48#include <klocale.h>
49#include <kglobal.h>
50#include <kfontdialog.h>
51#include <kmessagebox.h>
52#include <kcolordialog.h>
53#include <kiconloader.h>
54
55#include "kprefs.h"
56
57#include "kprefsdialog.h"
58#include "kprefsdialog.moc"
59
60KPrefsWidBool::KPrefsWidBool(const QString &text,bool *reference,
61 QWidget *parent)
62{
63 mReference = reference;
64
65 mCheck = new QCheckBox(text,parent);
66}
67
68void KPrefsWidBool::readConfig()
69{
70 mCheck->setChecked(*mReference);
71}
72
73void KPrefsWidBool::writeConfig()
74{
75 *mReference = mCheck->isChecked();
76}
77
78QCheckBox *KPrefsWidBool::checkBox()
79{
80 return mCheck;
81}
82
83
84KPrefsWidColor::KPrefsWidColor(const QString &text,QColor *reference,
85 QWidget *parent)
86{
87 mReference = reference;
88
89 mButton = new KColorButton(parent);
90 mLabel = new QLabel(mButton, text, parent);
91 mButton->setColor( *mReference );
92 mButton->setColor( Qt::red );
93
94}
95
96KPrefsWidColor::~KPrefsWidColor()
97{
98// kdDebug(5300) << "KPrefsWidColor::~KPrefsWidColor()" << endl;
99}
100
101void KPrefsWidColor::readConfig()
102{
103 mButton->setColor(*mReference);
104}
105
106void KPrefsWidColor::writeConfig()
107{
108 *mReference = mButton->color();
109}
110
111QLabel *KPrefsWidColor::label()
112{
113 return mLabel;
114}
115
116KColorButton *KPrefsWidColor::button()
117{
118 return mButton;
119}
120
121KPrefsWidFont::KPrefsWidFont(const QString &sampleText,const QString &labelText,
122 QFont *reference,QWidget *parent)
123{
124 mReference = reference;
125
126 mLabel = new QLabel(labelText, parent);
127
128 mPreview = new QLabel(sampleText,parent);
129 mPreview->setFrameStyle(QFrame::Panel|QFrame::Sunken);
130
131 mButton = new QPushButton(i18n("Choose..."), parent);
132 connect(mButton,SIGNAL(clicked()),SLOT(selectFont()));
133 mPreview->setMaximumHeight( QApplication::desktop()->height() / 12 );
134 mPreview->setMaximumWidth( (QApplication::desktop()->width() / 2)-10 );
135}
136
137KPrefsWidFont::~KPrefsWidFont()
138{
139}
140
141void KPrefsWidFont::readConfig()
142{
143 mPreview->setFont(*mReference);
144}
145
146void KPrefsWidFont::writeConfig()
147{
148 *mReference = mPreview->font();
149}
150
151QLabel *KPrefsWidFont::label()
152{
153 return mLabel;
154}
155
156QLabel *KPrefsWidFont::preview()
157{
158 return mPreview;
159}
160
161QPushButton *KPrefsWidFont::button()
162{
163 return mButton;
164}
165
166void KPrefsWidFont::selectFont()
167{
168 QFont myFont(mPreview->font());
169 bool ok;
170 myFont = KFontDialog::getFont(myFont, ok);
171 if ( ok ) {
172 mPreview->setFont(myFont);
173 }
174}
175
176
177KPrefsWidTime::KPrefsWidTime(const QString &text,int *reference,
178 QWidget *parent)
179{
180 mReference = reference;
181
182 mLabel = new QLabel(text,parent);
183 mSpin = new QSpinBox(0,23,1,parent);
184 mSpin->setSuffix(":00");
185}
186
187void KPrefsWidTime::readConfig()
188{
189 mSpin->setValue(*mReference);
190}
191
192void KPrefsWidTime::writeConfig()
193{
194 *mReference = mSpin->value();
195}
196
197QLabel *KPrefsWidTime::label()
198{
199 return mLabel;
200}
201
202QSpinBox *KPrefsWidTime::spinBox()
203{
204 return mSpin;
205}
206
207
208KPrefsWidRadios::KPrefsWidRadios(const QString &text,int *reference,
209 QWidget *parent)
210{
211 mReference = reference;
212
213 mBox = new QButtonGroup(1,Qt::Horizontal,text,parent);
214}
215
216KPrefsWidRadios::~KPrefsWidRadios()
217{
218}
219
220void KPrefsWidRadios::addRadio(const QString &text)
221{
222 new QRadioButton(text,mBox);
223}
224
225QButtonGroup *KPrefsWidRadios::groupBox()
226{
227 return mBox;
228}
229
230void KPrefsWidRadios::readConfig()
231{
232 mBox->setButton(*mReference);
233}
234
235void KPrefsWidRadios::writeConfig()
236{
237 *mReference = mBox->id(mBox->selected());
238}
239
240
241KPrefsWidString::KPrefsWidString(const QString &text,QString *reference,
242 QWidget *parent, QLineEdit::EchoMode echomode)
243{
244 mReference = reference;
245
246 mLabel = new QLabel(text,parent);
247 mEdit = new QLineEdit(parent);
248 mEdit->setEchoMode( echomode );
249}
250
251KPrefsWidString::~KPrefsWidString()
252{
253}
254
255void KPrefsWidString::readConfig()
256{
257 mEdit->setText(*mReference);
258}
259
260void KPrefsWidString::writeConfig()
261{
262 *mReference = mEdit->text();
263}
264
265QLabel *KPrefsWidString::label()
266{
267 return mLabel;
268}
269
270QLineEdit *KPrefsWidString::lineEdit()
271{
272 return mEdit;
273}
274
275
276KPrefsDialog::KPrefsDialog(KPrefs *prefs,QWidget *parent,char *name,bool modal) :
277 KDialogBase(IconList,i18n("Preferences"),Ok|Cancel|Default,Ok,parent,
278 name,modal,true)
279{
280 mPrefs = prefs;
281
282// This seems to cause a crash on exit. Investigate later.
283// mPrefsWids.setAutoDelete(true);
284
285 connect(this,SIGNAL(defaultClicked()),SLOT(slotDefault()));
286 //connect(this,SIGNAL(cancelClicked()),SLOT(slotDefault()));
287 //connect(this,SIGNAL(cancelClicked()),SLOT(reject()));
288}
289
290KPrefsDialog::~KPrefsDialog()
291{
292}
293
294void KPrefsDialog::addWid(KPrefsWid *wid)
295{
296 mPrefsWids.append(wid);
297}
298
299KPrefsWidBool *KPrefsDialog::addWidBool(const QString &text,bool *reference,QWidget *parent)
300{
301 KPrefsWidBool *w = new KPrefsWidBool(text,reference,parent);
302 addWid(w);
303 return w;
304}
305
306KPrefsWidTime *KPrefsDialog::addWidTime(const QString &text,int *reference,QWidget *parent)
307{
308 KPrefsWidTime *w = new KPrefsWidTime(text,reference,parent);
309 addWid(w);
310 return w;
311}
312
313KPrefsWidColor *KPrefsDialog::addWidColor(const QString &text,QColor *reference,QWidget *parent)
314{
315 KPrefsWidColor *w = new KPrefsWidColor(text,reference,parent);
316 addWid(w);
317 return w;
318}
319
320KPrefsWidRadios *KPrefsDialog::addWidRadios(const QString &text,int *reference,QWidget *parent)
321{
322 KPrefsWidRadios *w = new KPrefsWidRadios(text,reference,parent);
323 addWid(w);
324 return w;
325}
326
327KPrefsWidString *KPrefsDialog::addWidString(const QString &text,QString *reference,QWidget *parent)
328{
329 KPrefsWidString *w = new KPrefsWidString(text,reference,parent);
330 addWid(w);
331 return w;
332}
333
334KPrefsWidString *KPrefsDialog::addWidPassword(const QString &text,QString *reference,QWidget *parent)
335{
336 KPrefsWidString *w = new KPrefsWidString(text,reference,parent,QLineEdit::Password);
337 addWid(w);
338 return w;
339}
340
341KPrefsWidFont *KPrefsDialog::addWidFont(const QString &sampleText,const QString &buttonText,
342 QFont *reference,QWidget *parent)
343{
344 KPrefsWidFont *w = new KPrefsWidFont(sampleText,buttonText,reference,parent);
345 addWid(w);
346 return w;
347}
348
349void KPrefsDialog::setDefaults()
350{
351 mPrefs->setDefaults();
352
353 readConfig();
354}
355
356void KPrefsDialog::readConfig()
357{
358// kdDebug(5300) << "KPrefsDialog::readConfig()" << endl;
359
360 KPrefsWid *wid;
361 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
362 wid->readConfig();
363 }
364
365 usrReadConfig();
366}
367
368void KPrefsDialog::writeConfig()
369{
370// kdDebug(5300) << "KPrefsDialog::writeConfig()" << endl;
371
372 KPrefsWid *wid;
373 for(wid = mPrefsWids.first();wid;wid=mPrefsWids.next()) {
374 wid->writeConfig();
375 }
376
377 usrWriteConfig();
378
379// kdDebug(5300) << "KPrefsDialog::writeConfig() now writing..." << endl;
380
381 mPrefs->writeConfig();
382
383// kdDebug(5300) << "KPrefsDialog::writeConfig() done" << endl;
384}
385
386
387void KPrefsDialog::slotApply()
388{
389 writeConfig();
390 emit configChanged();
391}
392
393void KPrefsDialog::slotOk()
394{
395 slotApply();
396 QDialog::accept();
397}
398void KPrefsDialog::accept()
399{
400 slotOk();
401}
402
403void KPrefsDialog::slotDefault()
404{
405 if (KMessageBox::warningContinueCancel(this,
406 i18n("You are about to set all\npreferences to default values.\nAll "
407 "custom modifications will be lost."),i18n("Setting Default Preferences"),
408 i18n("Continue"))
409 == KMessageBox::Continue) setDefaults();
410}
diff --git a/libkdepim/kprefsdialog.h b/libkdepim/kprefsdialog.h
new file mode 100644
index 0000000..dceab01
--- a/dev/null
+++ b/libkdepim/kprefsdialog.h
@@ -0,0 +1,446 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23#ifndef _KPREFSDIALOG_H
24#define _KPREFSDIALOG_H
25// $Id$
26
27#include <qptrlist.h>
28#include <qlineedit.h>
29
30#include <kdialogbase.h>
31
32class KPrefs;
33class KPrefsDialog;
34
35class KColorButton;
36class QCheckBox;
37class QLabel;
38class QSpinBox;
39class QButtonGroup;
40
41/**
42 @short Base class for widgets used by @ref KPrefsDialog.
43 @author Cornelius Schumacher
44 @see KPrefsDialog
45
46 This class provides the interface for the preferences widgets used by
47 KPrefsDialog.
48*/
49class KPrefsWid
50{
51 public:
52 /**
53 This function is called to read value of the setting from the
54 stored configuration and display it in the widget.
55 */
56 virtual void readConfig() = 0;
57 /**
58 This function is called to write the current setting of the widget to the
59 stored configuration.
60 */
61 virtual void writeConfig() = 0;
62};
63
64/**
65 @short Widget for bool settings in @ref KPrefsDialog.
66
67 This class provides a widget for configuring bool values. It is meant to be
68 used by KPrefsDialog. The user is responsible for the layout management.
69*/
70class KPrefsWidBool : public KPrefsWid
71{
72 public:
73 /**
74 Create a bool widget consisting of a QCheckbox.
75
76 @param text Text of QCheckBox.
77 @param reference Pointer to variable read and written by this widget.
78 @param parent Parent widget.
79 */
80 KPrefsWidBool(const QString &text,bool *reference,QWidget *parent);
81
82 /**
83 Return the QCheckbox used by this widget.
84 */
85 QCheckBox *checkBox();
86
87 void readConfig();
88 void writeConfig();
89
90 private:
91 bool *mReference;
92
93 QCheckBox *mCheck;
94};
95
96/**
97 @short Widget for time settings in @ref KPrefsDialog.
98
99 This class provides a widget for configuring time values. It is meant to be
100 used by KPrefsDialog. The user is responsible for the layout management.
101*/
102class KPrefsWidTime : public KPrefsWid
103{
104 public:
105 /**
106 Create a time widget consisting of a label and a spinbox.
107
108 @param text Text of Label.
109 @param reference Pointer to variable read and written by this widget.
110 @param parent Parent widget.
111 */
112 KPrefsWidTime(const QString &text,int *reference,QWidget *parent);
113
114 /**
115 Return QLabel used by this widget.
116 */
117 QLabel *label();
118 /**
119 Return QSpinBox used by this widget.
120 */
121 QSpinBox *spinBox();
122
123 void readConfig();
124 void writeConfig();
125
126 private:
127 int *mReference;
128
129 QLabel *mLabel;
130 QSpinBox *mSpin;
131};
132
133/**
134 @short Widget for color settings in @ref KPrefsDialog.
135
136 This class provides a widget for configuring color values. It is meant to be
137 used by KPrefsDialog. The user is responsible for the layout management.
138*/
139class KPrefsWidColor : public QObject, public KPrefsWid
140{
141 Q_OBJECT
142 public:
143 /**
144 Create a color widget consisting of a test field and a button for opening
145 a color dialog.
146
147 @param text Text of button.
148 @param reference Pointer to variable read and written by this widget.
149 @param parent Parent widget.
150 */
151 KPrefsWidColor(const QString &text,QColor *reference,QWidget *parent);
152 /**
153 Destruct color setting widget.
154 */
155 ~KPrefsWidColor();
156
157 /**
158 Return QLabel for the button
159 */
160 QLabel *label();
161 /**
162 Return button opening the color dialog.
163 */
164 KColorButton *button();
165
166 void readConfig();
167 void writeConfig();
168
169 private:
170 QColor *mReference;
171
172 QLabel *mLabel;
173 KColorButton *mButton;
174};
175
176/**
177 @short Widget for font settings in @ref KPrefsDialog.
178
179 This class provides a widget for configuring font values. It is meant to be
180 used by KPrefsDialog. The user is responsible for the layout management.
181*/
182class KPrefsWidFont : public QObject, public KPrefsWid
183{
184 Q_OBJECT
185 public:
186 /**
187 Create a font widget consisting of a test field and a button for opening
188 a font dialog.
189
190 @param label Text of label.
191 @param reference Pointer to variable read and written by this widget.
192 @param parent Parent widget.
193 */
194 KPrefsWidFont(const QString &sampleText,const QString &labelText,
195 QFont *reference,QWidget *parent);
196 /**
197 Destruct font setting widget.
198 */
199 ~KPrefsWidFont();
200
201 /**
202 Return label.
203 */
204 QLabel *label();
205 /**
206 Return QFrame used as preview field.
207 */
208 QLabel *preview();
209 /**
210 Return button opening the font dialog.
211 */
212 QPushButton *button();
213
214 void readConfig();
215 void writeConfig();
216
217 protected slots:
218 void selectFont();
219
220 private:
221 QFont *mReference;
222
223 QLabel *mLabel;
224 QLabel *mPreview;
225 QPushButton *mButton;
226};
227
228/**
229 @short Widget for settings represented by a group of radio buttons in
230 @ref KPrefsDialog.
231
232 This class provides a widget for configuring selections. It is meant to be
233 used by KPrefsDialog. The user is responsible for the layout management. The
234 setting is interpreted as an int value, corresponding to the position of the
235 radio button. The position of the button is defined by the sequence of @ref
236 addRadio() calls, starting with 0.
237*/
238class KPrefsWidRadios : public KPrefsWid
239{
240 public:
241 /**
242 Create a widget for selection of an option. It consists of a box with
243 several radio buttons.
244
245 @param text Text of main box.
246 @param reference Pointer to variable read and written by this widget.
247 @param parent Parent widget.
248 */
249 KPrefsWidRadios(const QString &text,int *reference,QWidget *parent);
250 virtual ~KPrefsWidRadios();
251
252 /**
253 Add a radio button.
254
255 @param text Text of the button.
256 */
257 void addRadio(const QString &text);
258
259 /**
260 Return the box widget used by this widget.
261 */
262 QButtonGroup *groupBox();
263
264 void readConfig();
265 void writeConfig();
266
267 private:
268 int *mReference;
269
270 QButtonGroup *mBox;
271};
272
273
274/**
275 @short Widget for string settings in @ref KPrefsDialog.
276
277 This class provides a widget for configuring string values. It is meant to be
278 used by KPrefsDialog. The user is responsible for the layout management.
279*/
280class KPrefsWidString : public KPrefsWid
281{
282 public:
283 /**
284 Create a string widget consisting of a test label and a line edit.
285
286 @param text Text of label.
287 @param reference Pointer to variable read and written by this widget.
288 @param parent Parent widget.
289 */
290 KPrefsWidString(const QString &text,QString *reference,QWidget *parent,QLineEdit::EchoMode echomode=QLineEdit::Normal);
291 /**
292 Destructor.
293 */
294 virtual ~KPrefsWidString();
295
296 /**
297 Return label used by this widget.
298 */
299 QLabel *label();
300 /**
301 Return QLineEdit used by this widget.
302 */
303 QLineEdit *lineEdit();
304
305 void readConfig();
306 void writeConfig();
307
308 private:
309 QString *mReference;
310
311 QLabel *mLabel;
312 QLineEdit *mEdit;
313};
314
315
316/**
317 @short Base class for a preferences dialog.
318
319 This class provides the framework for a preferences dialog. You have to
320 subclass it and add the code to create the actual configuration widgets and
321 do the layout management.
322
323 KPrefsDialog provides functions to add subclasses of @ref KPrefsWid. For
324 these widgets the reading, writing and setting to default values is handled
325 automatically. Custom widgets have to be handled in the functions @ref
326 usrReadConfig() and @ref usrWriteConfig().
327*/
328class KPrefsDialog : public KDialogBase
329{
330 Q_OBJECT
331 public:
332 /**
333 Create a KPrefsDialog for a KPrefs object.
334
335 @param prefs KPrefs object used to access te configuration.
336 @param parent Parent widget.
337 @param name Widget name.
338 @param modal true, if dialog has to be modal, false for non-modal.
339 */
340 KPrefsDialog(KPrefs *prefs,QWidget *parent=0,char *name=0,bool modal=false);
341 /**
342 Destructor.
343 */
344 virtual ~KPrefsDialog();
345
346 /**
347 Register a custom KPrefsWid object.
348 */
349 void addWid(KPrefsWid *);
350 /**
351 Register a @ref KPrefsWidBool object.
352
353 @param text Text of bool widget.
354 @param reference Reference to variable storing the setting.
355 @param parent Parent widget.
356 */
357 KPrefsWidBool *addWidBool(const QString &text,bool *reference,QWidget *parent);
358 /**
359 Register a @ref KPrefsWidTime object.
360
361 @param text Text of time widget.
362 @param reference Reference to variable storing the setting.
363 @param parent Parent widget.
364 */
365 KPrefsWidTime *addWidTime(const QString &text,int *reference,QWidget *parent);
366 /**
367 Register a @ref KPrefsWidColor object.
368
369 @param text Text of color widget.
370 @param reference Reference to variable storing the setting.
371 @param parent Parent widget.
372 */
373 KPrefsWidColor *addWidColor(const QString &text,QColor *reference,QWidget *parent);
374 /**
375 Register a @ref KPrefsWidRadios object.
376
377 @param text Text of radio button box widget.
378 @param reference Reference to variable storing the setting.
379 @param parent Parent widget.
380 */
381 KPrefsWidRadios *addWidRadios(const QString &text,int *reference,QWidget *parent);
382 /**
383 Register a @ref KPrefsWidString object.
384
385 @param text Text of string widget.
386 @param reference Reference to variable storing the setting.
387 @param parent Parent widget.
388 */
389 KPrefsWidString *addWidString(const QString &text,QString *reference,QWidget *parent);
390 /**
391 Register a password @ref KPrefsWidString object, with echomode set to QLineEdit::Password.
392
393 @param text Text of string widget.
394 @param reference Reference to variable storing the setting.
395 @param parent Parent widget.
396 */
397 KPrefsWidString *addWidPassword (const QString &text,QString *reference,QWidget *parent);
398 /**
399 Register a @ref KPrefsWidFont object.
400
401 @param sampleText Sample text of font widget.
402 @param buttonText Button text of font widget.
403 @param reference Reference to variable storing the setting.
404 @param parent Parent widget.
405 */
406 KPrefsWidFont *addWidFont(const QString &sampleText,const QString &buttonText,
407 QFont *reference,QWidget *parent);
408
409 public slots:
410 /** Set all widgets to default values. */
411 void setDefaults();
412
413 /** Read preferences from config file. */
414 void readConfig();
415
416 /** Write preferences to config file. */
417 void writeConfig();
418
419 signals:
420 /** Emitted when the a changed configuration has been stored. */
421 void configChanged();
422
423 protected slots:
424 /** Apply changes to preferences */
425 void slotApply();
426
427 void accept();
428 /** Accept changes to preferences and close dialog */
429 void slotOk();
430
431 /** Set preferences to default values */
432 void slotDefault();
433
434 protected:
435 /** Implement this to read custom configuration widgets. */
436 virtual void usrReadConfig() {}
437 /** Implement this to write custom configuration widgets. */
438 virtual void usrWriteConfig() {}
439
440 private:
441 KPrefs *mPrefs;
442
443 QPtrList<KPrefsWid> mPrefsWids;
444};
445
446#endif
diff --git a/libkdepim/kprefsdialog.moc b/libkdepim/kprefsdialog.moc
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/libkdepim/kprefsdialog.moc
diff --git a/libkdepim/ksyncprofile.cpp b/libkdepim/ksyncprofile.cpp
new file mode 100644
index 0000000..d6d8fa3
--- a/dev/null
+++ b/libkdepim/ksyncprofile.cpp
@@ -0,0 +1,125 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21// $Id$
22
23#include <qcolor.h>
24
25#include <kconfig.h>
26#include <kstandarddirs.h>
27#include <kglobal.h>
28#include <kdebug.h>
29
30#include "ksyncprofile.h"
31
32
33KSyncProfile::KSyncProfile( const char * name): QObject (0, name )
34{
35 setDefault();
36}
37KSyncProfile::~KSyncProfile()
38{
39
40}
41
42
43KSyncProfile* KSyncProfile::clone()
44{
45 KSyncProfile* myClone = new KSyncProfile();
46 myClone->setPreSyncCommand( mPreSyncCommand );
47 myClone->setPostSyncCommand( mPostSyncCommand );
48 myClone->setLocalTempFile( mLocalTempFile);
49 myClone->setRemoteFileName( mRemoteFileName );
50 myClone->setShowSummaryAfterSync( mShowSummaryAfterSync );
51 myClone->setAskForPreferences( mAskForPreferences);
52 myClone->setWriteBackExisting(mWriteBackExisting );
53 myClone->setWriteBackFile( mWriteBackFile);
54 myClone->setIncludeInRingSync( mIncludeInRingSync );
55 myClone->setSyncPrefs( mSyncPrefs);
56 myClone->setIsLocalFileSync( mIsLocalFileSync );
57 myClone->setName( "noName" );
58 return myClone;
59}
60
61
62void KSyncProfile::setDefault()
63{
64 mName = "noName";
65 mPreSyncCommand = i18n("command for downloading remote file to local device");
66 mPostSyncCommand = i18n("command for uploading local temp file to remote device");
67 mLocalTempFile = "/tmp/mycalendar.ics";
68 mRemoteFileName = "/home/polo/kdepim/apps/korganizer/localfile.ics";
69 mShowSummaryAfterSync = true;
70 mAskForPreferences = true;
71 mWriteBackExisting = false;
72 mWriteBackFile = true;
73 mIncludeInRingSync = false;
74 mSyncPrefs = SYNC_PREF_ASK;
75 mIsLocalFileSync = true;
76
77}
78void KSyncProfile::readConfig(KConfig *config )
79{
80 config->setGroup("SyncProfiles");
81 QString prefix = "Profile_"+mName+"_";
82 //mName = config->readEntry( prefix+ "Name", mName );
83 mPreSyncCommand = config->readEntry( prefix+ "PreSyncCommand",mPreSyncCommand );
84 mPostSyncCommand = config->readEntry( prefix+ "PostSyncCommand", mPostSyncCommand );
85 mIncludeInRingSync = config->readBoolEntry( prefix+ "IncludeInRingSync",mIncludeInRingSync );
86 mLocalTempFile = config->readEntry( prefix+ "LocalTempFile", mLocalTempFile );
87 mRemoteFileName = config->readEntry( prefix+ "RemoteFileName", mRemoteFileName );
88 mShowSummaryAfterSync = config->readBoolEntry( prefix+ "ShowSummaryAfterSync", mShowSummaryAfterSync );
89 mAskForPreferences = config->readBoolEntry( prefix+ "AskForPreferences",mAskForPreferences );
90 mWriteBackExisting = config->readBoolEntry( prefix+ "WriteBackExisting",mWriteBackExisting );
91 mSyncPrefs = config->readNumEntry( prefix+ "SyncPrefs", mSyncPrefs );
92 mIsLocalFileSync= config->readBoolEntry( prefix+ "IsLocalFileSync", mIsLocalFileSync );
93}
94void KSyncProfile::writeConfig( KConfig * config )
95{
96 config->setGroup("SyncProfiles");
97 QString prefix = "Profile_"+mName+"_";
98 // config->writeEntry( prefix+ "Name", mName );
99 config->writeEntry( prefix+ "PreSyncCommand",mPreSyncCommand );
100 config->writeEntry( prefix+ "PostSyncCommand", mPostSyncCommand );
101 config->writeEntry( prefix+ "IncludeInRingSync",mIncludeInRingSync );
102 config->writeEntry( prefix+ "LocalTempFile", mLocalTempFile );
103 config->writeEntry( prefix+ "RemoteFileName", mRemoteFileName );
104 config->writeEntry( prefix+ "ShowSummaryAfterSync", mShowSummaryAfterSync );
105 config->writeEntry( prefix+ "AskForPreferences",mAskForPreferences );
106 config->writeEntry( prefix+ "WriteBackExisting",mWriteBackExisting );
107 config->writeEntry( prefix+ "SyncPrefs", mSyncPrefs );
108 config->writeEntry( prefix+ "IsLocalFileSync", mIsLocalFileSync );
109}
110
111/*
112class KPrefsItemInt : public KPrefsItem {
113 public:
114 KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0);
115 virtual ~KPrefsItemInt() {}
116
117 void setDefault();
118 void readConfig(KConfig *);
119 void writeConfig(KConfig *);
120
121 private:
122 int *mReference;
123 int mDefault;
124};
125*/
diff --git a/libkdepim/ksyncprofile.h b/libkdepim/ksyncprofile.h
new file mode 100644
index 0000000..238ffad
--- a/dev/null
+++ b/libkdepim/ksyncprofile.h
@@ -0,0 +1,106 @@
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20#ifndef _KSYNCPROFILE_H
21#define _KSYNCPROFILE_H
22
23#include <qptrlist.h>
24#include <qcolor.h>
25#include <qfont.h>
26#include <qstringlist.h>
27#include <qobject.h>
28#include <qstring.h>
29
30#define SYNC_PREF_LOCAL 0
31#define SYNC_PREF_REMOTE 1
32#define SYNC_PREF_NEWEST 2
33#define SYNC_PREF_ASK 3
34#define SYNC_PREF_FORCE_LOCAL 4
35#define SYNC_PREF_FORCE_REMOTE 5
36#define SYNC_PREF_TAKE_BOTH 6
37
38class KConfig;
39
40/**
41 @short Class for storing a preferences setting
42 @author Cornelius Schumacher
43 @see KPref
44
45 This class represents one preferences setting as used by @ref KPrefs.
46 Subclasses of KPrefsItem implement storage functions for a certain type of
47 setting. Normally you don't have to use this class directly. Use the special
48 addItem() functions of KPrefs instead. If you subclass this class you will
49 have to register instances with the function KPrefs::addItem().
50*/
51class KSyncProfile : public QObject {
52 public:
53 KSyncProfile( const char * name = 0);
54 ~KSyncProfile() ;
55
56 KSyncProfile* clone();
57 void setDefault();
58 void readConfig(KConfig *);
59 void writeConfig(KConfig *);
60 void setName( const QString& n ) {mName = n;}
61 QString getName( ) { return mName;}
62 void setPreSyncCommand( const QString& n ) {mPreSyncCommand = n;}
63 QString getPreSyncCommand( ) { return mPreSyncCommand; }
64 void setPostSyncCommand( const QString& n ) {mPostSyncCommand = n;}
65 QString getPostSyncCommand( ) { return mPostSyncCommand;}
66
67 void setLocalTempFile( const QString& n ) { mLocalTempFile= n;}
68 QString getLocalTempFile( ) { return mLocalTempFile;}
69 void setRemoteFileName( const QString& n ) { mRemoteFileName = n;}
70 QString getRemoteFileName( ) { return mRemoteFileName;}
71 /*
72 void set( const QString& n ) { = n;}
73 QString get( ) { return ;}
74 */
75
76 void setShowSummaryAfterSync( bool b ) { mShowSummaryAfterSync = b;}
77 bool getShowSummaryAfterSync( ) { return mShowSummaryAfterSync ;}
78 void setAskForPreferences( bool b ) { mAskForPreferences= b;}
79 bool getAskForPreferences( ) { return mAskForPreferences;}
80 void setWriteBackExisting( bool b ) { mWriteBackExisting = b;}
81 bool getWriteBackExisting( ) { return mWriteBackExisting;}
82 void setWriteBackFile( bool b ) { mWriteBackFile= b;}
83 bool getWriteBackFile( ) { return mWriteBackFile;}
84 void setIncludeInRingSync( bool b ) {mIncludeInRingSync = b;}
85 bool getIncludeInRingSync( ) { return mIncludeInRingSync;}
86 void setSyncPrefs( int n ) { mSyncPrefs= n;}
87 int getSyncPrefs( ) { return mSyncPrefs;}
88 void setIsLocalFileSync( bool b ) { mIsLocalFileSync= b;}
89 bool getIsLocalFileSync( ) { return mIsLocalFileSync;}
90
91 private:
92 QString mName;
93 QString mPreSyncCommand;
94 QString mPostSyncCommand;
95 QString mLocalTempFile;
96 QString mRemoteFileName;
97 bool mIncludeInRingSync;
98 int mSyncPrefs;
99 bool mWriteBackFile;
100 bool mWriteBackExisting;
101 bool mAskForPreferences;
102 bool mShowSummaryAfterSync;
103 bool mIsLocalFileSync;
104};
105
106#endif
diff --git a/libkdepim/libkdepim.pro b/libkdepim/libkdepim.pro
new file mode 100644
index 0000000..b490899
--- a/dev/null
+++ b/libkdepim/libkdepim.pro
@@ -0,0 +1,50 @@
1 TEMPLATE= lib
2 CONFIG = qt warn_on
3DEFINES +=KORG_NOKABC
4TARGET = microkdepim
5INCLUDEPATH += ../microkde ../libkabcwrap ../microkde/kdecore . ..
6DESTDIR=../bin
7
8DEFINES += DESKTOP_VERSION
9include( ../variables.pri )
10unix : {
11OBJECTS_DIR = obj/unix
12MOC_DIR = moc/unix
13}
14win32: {
15DEFINES += _WIN32_
16OBJECTS_DIR = obj/win
17MOC_DIR = moc/win
18}
19INTERFACES = \
20
21HEADERS = \
22 categoryeditdialog.h \
23 categoryeditdialog_base.h \
24 categoryselectdialog.h \
25 categoryselectdialog_base.h \
26 kdateedit.h \
27 kdatepicker.h \
28 kinputdialog.h \
29 kincidenceformatter.h \
30 kpimprefs.h \
31 kprefs.h \
32 kprefsdialog.h \
33 addresseeview.h \
34 ksyncprofile.h
35
36SOURCES = \
37 categoryeditdialog.cpp \
38 categoryeditdialog_base.cpp \
39 categoryselectdialog.cpp \
40 categoryselectdialog_base.cpp \
41 kdateedit.cpp \
42 kdatepicker.cpp \
43 kinputdialog.cpp \
44 kincidenceformatter.cpp \
45 kpimprefs.cpp \
46 kprefs.cpp \
47 kprefsdialog.cpp \
48 addresseeview.cpp \
49 ksyncprofile.cpp
50
diff --git a/libkdepim/libkdepimE.pro b/libkdepim/libkdepimE.pro
new file mode 100644
index 0000000..05abaa5
--- a/dev/null
+++ b/libkdepim/libkdepimE.pro
@@ -0,0 +1,43 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on
3TARGET = microkdepim
4INCLUDEPATH += ../microkde ../qtcompat ../libkabcwrap ../microkde/kdecore
5INCLUDEPATH += . ..
6LIBS += -lmicrokde
7OBJECTS_DIR = obj/$(PLATFORM)
8MOC_DIR = moc/$(PLATFORM)
9DESTDIR=$(QPEDIR)/lib
10
11
12INTERFACES = \
13
14HEADERS = \
15 categoryeditdialog.h \
16 categoryeditdialog_base.h \
17 categoryselectdialog.h \
18 categoryselectdialog_base.h \
19 kdateedit.h \
20 kdatepicker.h \
21 kinputdialog.h \
22 kincidenceformatter.h \
23 kpimprefs.h \
24 kprefs.h \
25 kprefsdialog.h \
26 addresseeview.h \
27 ksyncprofile.h
28
29
30SOURCES = \
31 categoryeditdialog.cpp \
32 categoryeditdialog_base.cpp \
33 categoryselectdialog.cpp \
34 categoryselectdialog_base.cpp \
35 kdateedit.cpp \
36 kinputdialog.cpp \
37 kdatepicker.cpp \
38 kincidenceformatter.cpp \
39 kpimprefs.cpp \
40 kprefs.cpp \
41 kprefsdialog.cpp \
42 addresseeview.cpp \
43 ksyncprofile.cpp