summaryrefslogtreecommitdiffabout
path: root/kaddressbook/kaddressbookmain.cpp
blob: 92c32caef2c6b2cd451af2248ca2410cf242339b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
    This file is part of KAddressbook.
    Copyright (c) 1999 Don Sanders <dsanders@kde.org>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#ifdef KAB_EMBEDDED
#include "kabprefs.h"
#include <kglobal.h>
#include <qmessagebox.h>
#include <qtoolbar.h>
#include <qapplication.h>
#else //KAB_EMBEDDED
#include <kedittoolbar.h>
#include <kkeydialog.h>
#include <kmessagebox.h>
#include <kstatusbar.h>
#endif //KAB_EMBEDDED
#include <klocale.h>

#include "kabcore.h"
#include "kaddressbookmain.h"
#include "kactioncollection.h"

#ifdef KAB_EMBEDDED
KAddressBookMain::KAddressBookMain() : KMainWindow( 0, "adrressbook" )
#else //KAB_EMBEDDED
//MOC_SKIP_BEGIN
KAddressBookMain::KAddressBookMain() : DCOPObject( "KAddressBookIface" ), KMainWindow( 0 ) 
//MOC_SKIP_END
#endif //KAB_EMBEDDED
{ 

    setIcon(SmallIcon( "ka24" )  );
#if 0
  //US for embedded systems, create the toolbar before we initiate KABCore.
  // KABCore will fill the toolbar with menues and icons
  QMainWindow::ToolBarDock tbd;
  tbd = Top;
  iconToolBar = new QToolBar( this );
  addToolBar (iconToolBar , tbd );
  iconToolBar->setHorizontalStretchable(true);  
//US  iconToolBar->setWidth(300);
#endif // 0

  mCore = new KABCore( this, true, this );
  
#ifdef KAB_EMBEDDED
  setCaption( i18n( "KAddressbook/Pi" ) );
#else //KAB_EMBEDDED
  setCaption( i18n( "Address Book Browser" ) );
#endif //KAB_EMBEDDED

  //mCore->restoreSettings();

  initActions();

  setCentralWidget( mCore );

//US  statusBar()->show();

#ifndef KAB_EMBEDDED
  setStandardToolBarMenuEnabled(true);
  
  createGUI( "kaddressbookui.rc", false );


#endif //KAB_EMBEDDED
  setAutoSaveSettings();
  qApp->processEvents();
  mCore->restoreSettings();
}

KAddressBookMain::~KAddressBookMain()
{
    // mCore->saveSettings();
}
#ifndef DESKTOP_VERSION
void KAddressBookMain::show () 
{
    static bool block = false;
    if( block ) {
        QWidget::show();
        return;
    } else {
        block = true ;
        QWidget::showFullScreen();
    }
    int min = 20;
    if ( QApplication::desktop()->width() > 320 )
        min += 20;
    setGeometry( 0,0,QApplication::desktop()->width(), QApplication::desktop()->height() - min );
    block = false;
}
#endif
void KAddressBookMain::showMinimized () 
{
    QWidget::showMinimized () ;
}
void KAddressBookMain::addEmail( QString addr )
{
  mCore->addEmail( addr );
}

#ifndef KAB_EMBEDDED
ASYNC KAddressBookMain::showContactEditor( QString uid )
{
  mCore->editContact( uid );
}
#endif //KAB_EMBEDDED
void KAddressBookMain::newContact()
{
  mCore->newContact();
}

QString KAddressBookMain::getNameByPhone( QString phone )
{
  return mCore->getNameByPhone( phone );
}

void KAddressBookMain::save()
{
  mCore->save();
}

void KAddressBookMain::exit()
{
  close( );
}

void KAddressBookMain::saveProperties( KConfig* )
{
}

void KAddressBookMain::readProperties( KConfig* )
{
}

void KAddressBookMain::initActions()
{
#ifndef KAB_EMBEDDED
  KStdAction::quit( this, SLOT( close() ), actionCollection() );
  KStdAction::configureToolbars( this, SLOT( configureToolbars() ), actionCollection() );
#else //KAB_EMBEDDED
  //US: transfered the setup of the actions into KABCore
#endif //KAB_EMBEDDED

  
}

//US new method to setup menues and toolbars on embedded systems
#ifdef KAB_EMBEDDED
/*
QToolBar * KAddressBookMain::getIconToolBar()
{
  return iconToolBar;
}
*/

void KAddressBookMain::createGUI()
{


    
}
#endif //KAB_EMBEDDED

void KAddressBookMain::configureToolbars()
{
#ifndef KAB_EMBEDDED
  saveMainWindowSettings( KGlobal::config(), "MainWindow" );

  KEditToolbar dlg( factory() );
  connect( &dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() ) );

  dlg.exec();
#else  //KAB_EMBEDDED
    qDebug("KAddressBookMain::configureToolbars() not implemented by ulf" );
#endif //KAB_EMBEDDED
}

void KAddressBookMain::slotNewToolbarConfig()
{
#ifndef KAB_EMBEDDED
  applyMainWindowSettings( KGlobal::config(), "MainWindow" );
#else  //KAB_EMBEDDED
    qDebug("KAddressBookMain::slotNewToolbarConfig() not implemented by ulf" );
#endif //KAB_EMBEDDED
}

void KAddressBookMain::configureKeys()
{
#ifndef KAB_EMBEDDED
  KKeyDialog::configureKeys( actionCollection(), xmlFile(), true, this );
#else  //KAB_EMBEDDED
    qDebug("KAddressBookMain::configureKeys() not implemented by ulf" );
#endif //KAB_EMBEDDED
}

void KAddressBookMain::closeEvent( QCloseEvent* ce )
{
    QString mess = i18n( "Close KA/Pi?");
    if ( mCore->modified() ) 
        mess += i18n( "\n\nChanges will be saved!");
    else
        mess += i18n( "\n\nNo unsaved changes detected!\nNothing will be  saved!");

 switch( QMessageBox::information( this, "KA/Pi", mess ,
                                      i18n("Yes!"), i18n("No"), 0, 0 ) ) {
    case 0:
     
        break;
    case 1:
        return;
	      break;
    case 2:
        return;
	      break;

    default:
        return;
      break;
    }

#if 0

  if ( mCore->modified() ) {
    QString text = i18n( "The address book has been modified.\nDo you want to save your changes?" );

#ifndef KAB_EMBEDDED
    int ret = KMessageBox::warningYesNoCancel( this, text, "",
                                              KStdGuiItem::yes(),
                                              KStdGuiItem::no(), "AskForSave" );
    switch ( ret ) {
      case KMessageBox::Yes:
        save();
        break;
      case KMessageBox::No:
        return true;
        break;
      default: //cancel
        return ;
        break;
    }

#else  //KAB_EMBEDDED
   switch( QMessageBox::information( this, "KA/Pi",
                                      text,
                                      i18n("Yes!"), i18n("No"), 0, 0 ) ) {
    case 0:
        save();
        break;
    case 1:
	      break;
    case 2:
        return;
    default:
        return;
      break;
    }
#endif //KAB_EMBEDDED
  }

#endif

  save();
  mCore->saveSettings();
  KABPrefs::instance()->writeConfig();
  ce->accept();
 
}

#ifndef KAB_EMBEDDED
#include "kaddressbookmain.moc"
#endif //KAB_EMBEDDED