author | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-06-26 19:01:18 (UTC) |
commit | b9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff) | |
tree | 2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kaddressbook/kaddressbookmain.cpp | |
download | kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2 |
Initial revision
Diffstat (limited to 'kaddressbook/kaddressbookmain.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/kaddressbookmain.cpp | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/kaddressbook/kaddressbookmain.cpp b/kaddressbook/kaddressbookmain.cpp new file mode 100644 index 0000000..92c32ca --- a/dev/null +++ b/kaddressbook/kaddressbookmain.cpp | |||
@@ -0,0 +1,293 @@ | |||
1 | /* | ||
2 | This file is part of KAddressbook. | ||
3 | Copyright (c) 1999 Don Sanders <dsanders@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 | #ifdef KAB_EMBEDDED | ||
25 | #include "kabprefs.h" | ||
26 | #include <kglobal.h> | ||
27 | #include <qmessagebox.h> | ||
28 | #include <qtoolbar.h> | ||
29 | #include <qapplication.h> | ||
30 | #else //KAB_EMBEDDED | ||
31 | #include <kedittoolbar.h> | ||
32 | #include <kkeydialog.h> | ||
33 | #include <kmessagebox.h> | ||
34 | #include <kstatusbar.h> | ||
35 | #endif //KAB_EMBEDDED | ||
36 | #include <klocale.h> | ||
37 | |||
38 | #include "kabcore.h" | ||
39 | #include "kaddressbookmain.h" | ||
40 | #include "kactioncollection.h" | ||
41 | |||
42 | #ifdef KAB_EMBEDDED | ||
43 | KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" ) | ||
44 | #else //KAB_EMBEDDED | ||
45 | //MOC_SKIP_BEGIN | ||
46 | KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 ) | ||
47 | //MOC_SKIP_END | ||
48 | #endif //KAB_EMBEDDED | ||
49 | { | ||
50 | |||
51 | setIcon(SmallIcon( "ka24" ) ); | ||
52 | #if 0 | ||
53 | //US for embedded systems, create the toolbar before we initiate KABCore. | ||
54 | // KABCore will fill the toolbar with menues and icons | ||
55 | QMainWindow::ToolBarDock tbd; | ||
56 | tbd = Top; | ||
57 | iconToolBar = new QToolBar( this ); | ||
58 | addToolBar (iconToolBar , tbd ); | ||
59 | iconToolBar->setHorizontalStretchable(true); | ||
60 | //US iconToolBar->setWidth(300); | ||
61 | #endif // 0 | ||
62 | |||
63 | mCore = new KABCore( this, true, this ); | ||
64 | |||
65 | #ifdef KAB_EMBEDDED | ||
66 | setCaption( i18n( "KAddressbook/Pi" ) ); | ||
67 | #else //KAB_EMBEDDED | ||
68 | setCaption( i18n( "Address Book Browser" ) ); | ||
69 | #endif //KAB_EMBEDDED | ||
70 | |||
71 | //mCore->restoreSettings(); | ||
72 | |||
73 | initActions(); | ||
74 | |||
75 | setCentralWidget( mCore ); | ||
76 | |||
77 | //US statusBar()->show(); | ||
78 | |||
79 | #ifndef KAB_EMBEDDED | ||
80 | setStandardToolBarMenuEnabled(true); | ||
81 | |||
82 | createGUI( "kaddressbookui.rc", false ); | ||
83 | |||
84 | |||
85 | #endif //KAB_EMBEDDED | ||
86 | setAutoSaveSettings(); | ||
87 | qApp->processEvents(); | ||
88 | mCore->restoreSettings(); | ||
89 | } | ||
90 | |||
91 | KAddressBookMain::~KAddressBookMain() | ||
92 | { | ||
93 | // mCore->saveSettings(); | ||
94 | } | ||
95 | #ifndef DESKTOP_VERSION | ||
96 | void KAddressBookMain::show () | ||
97 | { | ||
98 | static bool block = false; | ||
99 | if( block ) { | ||
100 | QWidget::show(); | ||
101 | return; | ||
102 | } else { | ||
103 | block = true ; | ||
104 | QWidget::showFullScreen(); | ||
105 | } | ||
106 | int min = 20; | ||
107 | if ( QApplication::desktop()->width() > 320 ) | ||
108 | min += 20; | ||
109 | setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min ); | ||
110 | block = false; | ||
111 | } | ||
112 | #endif | ||
113 | void KAddressBookMain::showMinimized () | ||
114 | { | ||
115 | QWidget::showMinimized () ; | ||
116 | } | ||
117 | void KAddressBookMain::addEmail( QString addr ) | ||
118 | { | ||
119 | mCore->addEmail( addr ); | ||
120 | } | ||
121 | |||
122 | #ifndef KAB_EMBEDDED | ||
123 | ASYNC KAddressBookMain::showContactEditor( QString uid ) | ||
124 | { | ||
125 | mCore->editContact( uid ); | ||
126 | } | ||
127 | #endif //KAB_EMBEDDED | ||
128 | void KAddressBookMain::newContact() | ||
129 | { | ||
130 | mCore->newContact(); | ||
131 | } | ||
132 | |||
133 | QString KAddressBookMain::getNameByPhone( QString phone ) | ||
134 | { | ||
135 | return mCore->getNameByPhone( phone ); | ||
136 | } | ||
137 | |||
138 | void KAddressBookMain::save() | ||
139 | { | ||
140 | mCore->save(); | ||
141 | } | ||
142 | |||
143 | void KAddressBookMain::exit() | ||
144 | { | ||
145 | close( ); | ||
146 | } | ||
147 | |||
148 | void KAddressBookMain::saveProperties( KConfig* ) | ||
149 | { | ||
150 | } | ||
151 | |||
152 | void KAddressBookMain::readProperties( KConfig* ) | ||
153 | { | ||
154 | } | ||
155 | |||
156 | void KAddressBookMain::initActions() | ||
157 | { | ||
158 | #ifndef KAB_EMBEDDED | ||
159 | KStdAction::quit( this, SLOT( close() ), actionCollection() ); | ||
160 | KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() ); | ||
161 | #else //KAB_EMBEDDED | ||
162 | //US: transfered the setup of the actions into KABCore | ||
163 | #endif //KAB_EMBEDDED | ||
164 | |||
165 | |||
166 | } | ||
167 | |||
168 | //US new method to setup menues and toolbars on embedded systems | ||
169 | #ifdef KAB_EMBEDDED | ||
170 | /* | ||
171 | QToolBar * KAddressBookMain::getIconToolBar() | ||
172 | { | ||
173 | return iconToolBar; | ||
174 | } | ||
175 | */ | ||
176 | |||
177 | void KAddressBookMain::createGUI() | ||
178 | { | ||
179 | |||
180 | |||
181 | |||
182 | } | ||
183 | #endif //KAB_EMBEDDED | ||
184 | |||
185 | void KAddressBookMain::configureToolbars() | ||
186 | { | ||
187 | #ifndef KAB_EMBEDDED | ||
188 | saveMainWindowSettings( KGlobal::config(), "MainWindow" ); | ||
189 | |||
190 | KEditToolbar dlg( factory() ); | ||
191 | connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) ); | ||
192 | |||
193 | dlg.exec(); | ||
194 | #else //KAB_EMBEDDED | ||
195 | qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" ); | ||
196 | #endif //KAB_EMBEDDED | ||
197 | } | ||
198 | |||
199 | void KAddressBookMain::slotNewToolbarConfig() | ||
200 | { | ||
201 | #ifndef KAB_EMBEDDED | ||
202 | applyMainWindowSettings( KGlobal::config(), "MainWindow" ); | ||
203 | #else //KAB_EMBEDDED | ||
204 | qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" ); | ||
205 | #endif //KAB_EMBEDDED | ||
206 | } | ||
207 | |||
208 | void KAddressBookMain::configureKeys() | ||
209 | { | ||
210 | #ifndef KAB_EMBEDDED | ||
211 | KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this ); | ||
212 | #else //KAB_EMBEDDED | ||
213 | qDebug("KAddressBookMain::configureKeys() not implemented by ulf" ); | ||
214 | #endif //KAB_EMBEDDED | ||
215 | } | ||
216 | |||
217 | void KAddressBookMain::closeEvent( QCloseEvent* ce ) | ||
218 | { | ||
219 | QString mess = i18n( "Close KA/Pi?"); | ||
220 | if ( mCore->modified() ) | ||
221 | mess += i18n( "\n\nChanges will be saved!"); | ||
222 | else | ||
223 | mess += i18n( "\n\nNo unsaved changes detected!\nNothing will be saved!"); | ||
224 | |||
225 | switch( QMessageBox::information( this, "KA/Pi", mess , | ||
226 | i18n("Yes!"), i18n("No"), 0, 0 ) ) { | ||
227 | case 0: | ||
228 | |||
229 | break; | ||
230 | case 1: | ||
231 | return; | ||
232 | break; | ||
233 | case 2: | ||
234 | return; | ||
235 | break; | ||
236 | |||
237 | default: | ||
238 | return; | ||
239 | break; | ||
240 | } | ||
241 | |||
242 | #if 0 | ||
243 | |||
244 | if ( mCore->modified() ) { | ||
245 | QString text = i18n( "The address book has been modified.\nDo you want to save your changes?" ); | ||
246 | |||
247 | #ifndef KAB_EMBEDDED | ||
248 | int ret = KMessageBox::warningYesNoCancel( this, text, "", | ||
249 | KStdGuiItem::yes(), | ||
250 | KStdGuiItem::no(), "AskForSave" ); | ||
251 | switch ( ret ) { | ||
252 | case KMessageBox::Yes: | ||
253 | save(); | ||
254 | break; | ||
255 | case KMessageBox::No: | ||
256 | return true; | ||
257 | break; | ||
258 | default: //cancel | ||
259 | return ; | ||
260 | break; | ||
261 | } | ||
262 | |||
263 | #else //KAB_EMBEDDED | ||
264 | switch( QMessageBox::information( this, "KA/Pi", | ||
265 | text, | ||
266 | i18n("Yes!"), i18n("No"), 0, 0 ) ) { | ||
267 | case 0: | ||
268 | save(); | ||
269 | break; | ||
270 | case 1: | ||
271 | break; | ||
272 | case 2: | ||
273 | return; | ||
274 | default: | ||
275 | return; | ||
276 | break; | ||
277 | } | ||
278 | #endif //KAB_EMBEDDED | ||
279 | } | ||
280 | |||
281 | #endif | ||
282 | |||
283 | save(); | ||
284 | mCore->saveSettings(); | ||
285 | KABPrefs::instance()->writeConfig(); | ||
286 | ce->accept(); | ||
287 | |||
288 | } | ||
289 | |||
290 | #ifndef KAB_EMBEDDED | ||
291 | #include "kaddressbookmain.moc" | ||
292 | #endif //KAB_EMBEDDED | ||
293 | |||