Diffstat (limited to 'kaddressbook/kaddressbookmain.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kaddressbook/kaddressbookmain.cpp | 86 |
1 files changed, 25 insertions, 61 deletions
diff --git a/kaddressbook/kaddressbookmain.cpp b/kaddressbook/kaddressbookmain.cpp index 8ebb93a..f48f214 100644 --- a/kaddressbook/kaddressbookmain.cpp +++ b/kaddressbook/kaddressbookmain.cpp | |||
@@ -1,276 +1,240 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 1999 Don Sanders <dsanders@kde.org> | 3 | Copyright (c) 1999 Don Sanders <dsanders@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 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 | 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. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #ifdef KAB_EMBEDDED | 24 | #ifdef KAB_EMBEDDED |
25 | #include "kabprefs.h" | 25 | #include "kabprefs.h" |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qtoolbar.h> | 28 | #include <qtoolbar.h> |
29 | #include <qapplication.h> | 29 | #include <qapplication.h> |
30 | #else //KAB_EMBEDDED | 30 | #else //KAB_EMBEDDED |
31 | #include <kedittoolbar.h> | 31 | #include <kedittoolbar.h> |
32 | #include <kkeydialog.h> | 32 | #include <kkeydialog.h> |
33 | #include <kmessagebox.h> | 33 | #include <kmessagebox.h> |
34 | #include <kstatusbar.h> | 34 | #include <kstatusbar.h> |
35 | #endif //KAB_EMBEDDED | 35 | #endif //KAB_EMBEDDED |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | 37 | ||
38 | #include "kabcore.h" | 38 | #include "kabcore.h" |
39 | #include "kaddressbookmain.h" | 39 | #include "kaddressbookmain.h" |
40 | #include "kactioncollection.h" | 40 | #include "kactioncollection.h" |
41 | 41 | ||
42 | #ifdef KAB_EMBEDDED | 42 | #ifdef KAB_EMBEDDED |
43 | KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" ) | 43 | KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" ) |
44 | #else //KAB_EMBEDDED | 44 | #else //KAB_EMBEDDED |
45 | //MOC_SKIP_BEGIN | 45 | //MOC_SKIP_BEGIN |
46 | KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 ) | 46 | KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 ) |
47 | //MOC_SKIP_END | 47 | //MOC_SKIP_END |
48 | #endif //KAB_EMBEDDED | 48 | #endif //KAB_EMBEDDED |
49 | { | 49 | { |
50 | 50 | ||
51 | setIcon(SmallIcon( "ka24" ) ); | 51 | setIcon(SmallIcon( "ka24" ) ); |
52 | #if 0 | 52 | #if 0 |
53 | //US for embedded systems, create the toolbar before we initiate KABCore. | 53 | //US for embedded systems, create the toolbar before we initiate KABCore. |
54 | // KABCore will fill the toolbar with menues and icons | 54 | // KABCore will fill the toolbar with menues and icons |
55 | QMainWindow::ToolBarDock tbd; | 55 | QMainWindow::ToolBarDock tbd; |
56 | tbd = Top; | 56 | tbd = Top; |
57 | iconToolBar = new QToolBar( this ); | 57 | iconToolBar = new QToolBar( this ); |
58 | addToolBar (iconToolBar , tbd ); | 58 | addToolBar (iconToolBar , tbd ); |
59 | iconToolBar->setHorizontalStretchable(true); | 59 | iconToolBar->setHorizontalStretchable(true); |
60 | //US iconToolBar->setWidth(300); | 60 | //US iconToolBar->setWidth(300); |
61 | #endif // 0 | 61 | #endif // 0 |
62 | 62 | ||
63 | mCore = new KABCore( this, true, this ); | 63 | mCore = new KABCore( this, true, this ); |
64 | 64 | ||
65 | #ifdef KAB_EMBEDDED | 65 | #ifdef KAB_EMBEDDED |
66 | setCaption( i18n( "KAddressbook/Pi" ) ); | 66 | setCaption( i18n( "KAddressbook/Pi" ) ); |
67 | #else //KAB_EMBEDDED | 67 | #else //KAB_EMBEDDED |
68 | setCaption( i18n( "Address Book Browser" ) ); | 68 | setCaption( i18n( "Address Book Browser" ) ); |
69 | #endif //KAB_EMBEDDED | 69 | #endif //KAB_EMBEDDED |
70 | 70 | ||
71 | //mCore->restoreSettings(); | 71 | //mCore->restoreSettings(); |
72 | 72 | ||
73 | initActions(); | 73 | initActions(); |
74 | 74 | ||
75 | setCentralWidget( mCore ); | 75 | setCentralWidget( mCore ); |
76 | 76 | ||
77 | //US statusBar()->show(); | 77 | //US statusBar()->show(); |
78 | 78 | ||
79 | #ifndef KAB_EMBEDDED | 79 | #ifndef KAB_EMBEDDED |
80 | setStandardToolBarMenuEnabled(true); | 80 | setStandardToolBarMenuEnabled(true); |
81 | 81 | ||
82 | createGUI( "kaddressbookui.rc", false ); | 82 | createGUI( "kaddressbookui.rc", false ); |
83 | 83 | ||
84 | 84 | ||
85 | #endif //KAB_EMBEDDED | 85 | #endif //KAB_EMBEDDED |
86 | setAutoSaveSettings(); | 86 | setAutoSaveSettings(); |
87 | qApp->processEvents(); | 87 | qApp->processEvents(); |
88 | mCore->restoreSettings(); | 88 | mCore->restoreSettings(); |
89 | } | 89 | } |
90 | 90 | ||
91 | KAddressBookMain::~KAddressBookMain() | 91 | KAddressBookMain::~KAddressBookMain() |
92 | { | 92 | { |
93 | // mCore->saveSettings(); | 93 | // mCore->saveSettings(); |
94 | } | 94 | } |
95 | 95 | ||
96 | void KAddressBookMain::showMinimized () | 96 | void KAddressBookMain::showMinimized () |
97 | { | 97 | { |
98 | QWidget::showMinimized () ; | 98 | QWidget::showMinimized () ; |
99 | } | 99 | } |
100 | void KAddressBookMain::addEmail( QString addr ) | 100 | void KAddressBookMain::addEmail( QString addr ) |
101 | { | 101 | { |
102 | mCore->addEmail( addr ); | 102 | mCore->addEmail( addr ); |
103 | } | 103 | } |
104 | 104 | ||
105 | #ifndef KAB_EMBEDDED | 105 | #ifndef KAB_EMBEDDED |
106 | ASYNC KAddressBookMain::showContactEditor( QString uid ) | 106 | ASYNC KAddressBookMain::showContactEditor( QString uid ) |
107 | { | 107 | { |
108 | mCore->editContact( uid ); | 108 | mCore->editContact( uid ); |
109 | } | 109 | } |
110 | #endif //KAB_EMBEDDED | 110 | #endif //KAB_EMBEDDED |
111 | void KAddressBookMain::newContact() | 111 | void KAddressBookMain::newContact() |
112 | { | 112 | { |
113 | mCore->newContact(); | 113 | mCore->newContact(); |
114 | } | 114 | } |
115 | 115 | ||
116 | QString KAddressBookMain::getNameByPhone( QString phone ) | 116 | QString KAddressBookMain::getNameByPhone( QString phone ) |
117 | { | 117 | { |
118 | return mCore->getNameByPhone( phone ); | 118 | return mCore->getNameByPhone( phone ); |
119 | } | 119 | } |
120 | 120 | ||
121 | void KAddressBookMain::save() | 121 | void KAddressBookMain::save() |
122 | { | 122 | { |
123 | mCore->save(); | 123 | mCore->save(); |
124 | } | 124 | } |
125 | 125 | ||
126 | void KAddressBookMain::exit() | 126 | void KAddressBookMain::exit() |
127 | { | 127 | { |
128 | close( ); | 128 | close( ); |
129 | } | 129 | } |
130 | 130 | ||
131 | void KAddressBookMain::saveProperties( KConfig* ) | 131 | void KAddressBookMain::saveProperties( KConfig* ) |
132 | { | 132 | { |
133 | } | 133 | } |
134 | 134 | ||
135 | void KAddressBookMain::readProperties( KConfig* ) | 135 | void KAddressBookMain::readProperties( KConfig* ) |
136 | { | 136 | { |
137 | } | 137 | } |
138 | 138 | ||
139 | void KAddressBookMain::initActions() | 139 | void KAddressBookMain::initActions() |
140 | { | 140 | { |
141 | #ifndef KAB_EMBEDDED | 141 | #ifndef KAB_EMBEDDED |
142 | KStdAction::quit( this, SLOT( close() ), actionCollection() ); | 142 | KStdAction::quit( this, SLOT( close() ), actionCollection() ); |
143 | KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() ); | 143 | KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() ); |
144 | #else //KAB_EMBEDDED | 144 | #else //KAB_EMBEDDED |
145 | //US: transfered the setup of the actions into KABCore | 145 | //US: transfered the setup of the actions into KABCore |
146 | #endif //KAB_EMBEDDED | 146 | #endif //KAB_EMBEDDED |
147 | 147 | ||
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | //US new method to setup menues and toolbars on embedded systems | 151 | //US new method to setup menues and toolbars on embedded systems |
152 | #ifdef KAB_EMBEDDED | 152 | #ifdef KAB_EMBEDDED |
153 | /* | 153 | /* |
154 | QToolBar * KAddressBookMain::getIconToolBar() | 154 | QToolBar * KAddressBookMain::getIconToolBar() |
155 | { | 155 | { |
156 | return iconToolBar; | 156 | return iconToolBar; |
157 | } | 157 | } |
158 | */ | 158 | */ |
159 | 159 | ||
160 | void KAddressBookMain::createGUI() | 160 | void KAddressBookMain::createGUI() |
161 | { | 161 | { |
162 | 162 | ||
163 | 163 | ||
164 | 164 | ||
165 | } | 165 | } |
166 | #endif //KAB_EMBEDDED | 166 | #endif //KAB_EMBEDDED |
167 | 167 | ||
168 | void KAddressBookMain::configureToolbars() | 168 | void KAddressBookMain::configureToolbars() |
169 | { | 169 | { |
170 | #ifndef KAB_EMBEDDED | 170 | #ifndef KAB_EMBEDDED |
171 | saveMainWindowSettings( KGlobal::config(), "MainWindow" ); | 171 | saveMainWindowSettings( KGlobal::config(), "MainWindow" ); |
172 | 172 | ||
173 | KEditToolbar dlg( factory() ); | 173 | KEditToolbar dlg( factory() ); |
174 | connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) ); | 174 | connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) ); |
175 | 175 | ||
176 | dlg.exec(); | 176 | dlg.exec(); |
177 | #else //KAB_EMBEDDED | 177 | #else //KAB_EMBEDDED |
178 | qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" ); | 178 | qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" ); |
179 | #endif //KAB_EMBEDDED | 179 | #endif //KAB_EMBEDDED |
180 | } | 180 | } |
181 | 181 | ||
182 | void KAddressBookMain::slotNewToolbarConfig() | 182 | void KAddressBookMain::slotNewToolbarConfig() |
183 | { | 183 | { |
184 | #ifndef KAB_EMBEDDED | 184 | #ifndef KAB_EMBEDDED |
185 | applyMainWindowSettings( KGlobal::config(), "MainWindow" ); | 185 | applyMainWindowSettings( KGlobal::config(), "MainWindow" ); |
186 | #else //KAB_EMBEDDED | 186 | #else //KAB_EMBEDDED |
187 | qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" ); | 187 | qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" ); |
188 | #endif //KAB_EMBEDDED | 188 | #endif //KAB_EMBEDDED |
189 | } | 189 | } |
190 | 190 | ||
191 | void KAddressBookMain::configureKeys() | 191 | void KAddressBookMain::configureKeys() |
192 | { | 192 | { |
193 | #ifndef KAB_EMBEDDED | 193 | #ifndef KAB_EMBEDDED |
194 | KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this ); | 194 | KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this ); |
195 | #else //KAB_EMBEDDED | 195 | #else //KAB_EMBEDDED |
196 | qDebug("KAddressBookMain::configureKeys() not implemented by ulf" ); | 196 | qDebug("KAddressBookMain::configureKeys() not implemented by ulf" ); |
197 | #endif //KAB_EMBEDDED | 197 | #endif //KAB_EMBEDDED |
198 | } | 198 | } |
199 | 199 | ||
200 | void KAddressBookMain::closeEvent( QCloseEvent* ce ) | 200 | void KAddressBookMain::closeEvent( QCloseEvent* ce ) |
201 | { | 201 | { |
202 | QString mess = i18n( "Close KA/Pi?"); | 202 | bool mModified = mCore->modified(); |
203 | if ( mCore->modified() ) | 203 | bool mAskForQuit = KABPrefs::instance()->mAskForQuit; |
204 | mess += i18n( "\n\nChanges will be saved!"); | ||
205 | else | ||
206 | mess += i18n( "\n\nNo unsaved changes detected!\nNothing will be saved!"); | ||
207 | |||
208 | switch( QMessageBox::information( this, "KA/Pi", mess , | ||
209 | i18n("Yes!"), i18n("No"), 0, 0 ) ) { | ||
210 | case 0: | ||
211 | |||
212 | break; | ||
213 | case 1: | ||
214 | return; | ||
215 | break; | ||
216 | case 2: | ||
217 | return; | ||
218 | break; | ||
219 | |||
220 | default: | ||
221 | return; | ||
222 | break; | ||
223 | } | ||
224 | 204 | ||
225 | #if 0 | 205 | QString mess = i18n( "Close KA/Pi?"); |
206 | if ( mModified == true ) | ||
207 | mess += i18n( "\nChanges will be saved!"); | ||
208 | else | ||
209 | mess += i18n( "\nNo unsaved changes detected!\nNothing will be saved!"); | ||
226 | 210 | ||
227 | if ( mCore->modified() ) { | 211 | bool mQuit = true; |
228 | QString text = i18n( "The address book has been modified.\nDo you want to save your changes?" ); | ||
229 | 212 | ||
230 | #ifndef KAB_EMBEDDED | ||
231 | int ret = KMessageBox::warningYesNoCancel( this, text, "", | ||
232 | KStdGuiItem::yes(), | ||
233 | KStdGuiItem::no(), "AskForSave" ); | ||
234 | switch ( ret ) { | ||
235 | case KMessageBox::Yes: | ||
236 | save(); | ||
237 | break; | ||
238 | case KMessageBox::No: | ||
239 | return true; | ||
240 | break; | ||
241 | default: //cancel | ||
242 | return ; | ||
243 | break; | ||
244 | } | ||
245 | 213 | ||
246 | #else //KAB_EMBEDDED | 214 | if (mAskForQuit) |
247 | switch( QMessageBox::information( this, "KA/Pi", | 215 | { |
248 | text, | 216 | |
249 | i18n("Yes!"), i18n("No"), 0, 0 ) ) { | 217 | int res = QMessageBox::information( this, "KA/Pi", mess , i18n("Yes!"), i18n("No"), 0, 0 ); |
250 | case 0: | 218 | if (res == 0) |
251 | save(); | 219 | mQuit = true; |
252 | break; | 220 | else |
253 | case 1: | 221 | mQuit = false; |
254 | break; | ||
255 | case 2: | ||
256 | return; | ||
257 | default: | ||
258 | return; | ||
259 | break; | ||
260 | } | ||
261 | #endif //KAB_EMBEDDED | ||
262 | } | 222 | } |
263 | 223 | ||
264 | #endif | 224 | if (mQuit == false) |
225 | return; | ||
226 | |||
227 | if (mModified == true) | ||
228 | { | ||
229 | save(); | ||
230 | mCore->saveSettings(); | ||
231 | KABPrefs::instance()->writeConfig(); | ||
232 | } | ||
265 | 233 | ||
266 | save(); | ||
267 | mCore->saveSettings(); | ||
268 | KABPrefs::instance()->writeConfig(); | ||
269 | ce->accept(); | 234 | ce->accept(); |
270 | |||
271 | } | 235 | } |
272 | 236 | ||
273 | #ifndef KAB_EMBEDDED | 237 | #ifndef KAB_EMBEDDED |
274 | #include "kaddressbookmain.moc" | 238 | #include "kaddressbookmain.moc" |
275 | #endif //KAB_EMBEDDED | 239 | #endif //KAB_EMBEDDED |
276 | 240 | ||