~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to kde/src/SFLPhoneView.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-19 21:46:37 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120519214637-la8rbrford5kj6m3
Tags: 1.1.0-1
* New upstream release 
  - Fixes "FTBFS with libccrtp-dev/2.0.2 from experimental" (Closes: #663282)
* NEW Maintainer: Debian VoIP Team - Thanks Francois for your work.
  - (Closes: #665789: O: sflphone -- SIP and IAX2 compatible VoIP phone)
* Added Build-Depends: libdbus-c++-bin
* Add gcc47-fixes.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2009-2012 by Savoir-Faire Linux                         *
3
 
 *   Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>         *
4
 
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
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 3 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                         *
18
 
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 
 **************************************************************************/
21
 
 
22
 
//Parent
23
 
#include "SFLPhoneView.h"
24
 
 
25
 
//Qt
26
 
#include <QtCore/QString>
27
 
#include <QtGui/QContextMenuEvent>
28
 
#include <QtGui/QPalette>
29
 
#include <QtGui/QInputDialog>
30
 
#include <QtGui/QWidget>
31
 
#include <QErrorMessage>
32
 
 
33
 
//KDE
34
 
#include <KLocale>
35
 
#include <KAction>
36
 
#include <KMenu>
37
 
#include <kabc/addressbook.h>
38
 
 
39
 
//SFLPhone
40
 
#include "conf/ConfigurationDialog.h"
41
 
#include "conf/ConfigurationSkeleton.h"
42
 
#include "AccountWizard.h"
43
 
#include "ActionSetAccountFirst.h"
44
 
#include "SFLPhone.h"
45
 
 
46
 
//SFLPhone library
47
 
#include "lib/typedefs.h"
48
 
#include "lib/configurationmanager_interface_singleton.h"
49
 
#include "lib/callmanager_interface_singleton.h"
50
 
#include "lib/instance_interface_singleton.h"
51
 
#include "lib/sflphone_const.h"
52
 
 
53
 
//ConfigurationDialog* SFLPhoneView::configDialog;
54
 
 
55
 
///Constructor
56
 
SFLPhoneView::SFLPhoneView(QWidget *parent)
57
 
   : QWidget(parent),
58
 
     wizard(0), errorWindow(0)
59
 
{
60
 
   setupUi(this);
61
 
 
62
 
   ConfigurationManagerInterface& configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
63
 
 
64
 
 
65
 
   callTreeModel->setTitle(i18n("Calls"));
66
 
 
67
 
   QPalette pal = QPalette(palette());
68
 
   pal.setColor(QPalette::AlternateBase, Qt::lightGray);
69
 
   setPalette(pal);
70
 
 
71
 
   //                SENDER                                        SIGNAL                             RECEIVER                                            SLOT                                  /
72
 
   /**/connect(SFLPhone::model()                     , SIGNAL(incomingCall(Call*))                   , this                                  , SLOT(on1_incomingCall(Call*)                    ));
73
 
   /**/connect(SFLPhone::model()                     , SIGNAL(voiceMailNotify(const QString &, int)) , this                                  , SLOT(on1_voiceMailNotify(const QString &, int)  ));
74
 
   /**/connect(callTreeModel                         , SIGNAL(itemChanged(Call*))                    , this                                  , SLOT(updateWindowCallState()                    ));
75
 
   /**///connect(SFLPhone::model()                     , SIGNAL(volumeChanged(const QString &, double)), this                                , SLOT(on1_volumeChanged(const QString &, double) ));
76
 
   /**/connect(SFLPhone::model()                     , SIGNAL(callStateChanged(Call*))               , this                                  , SLOT(updateWindowCallState()                    ));
77
 
   /**/connect(TreeWidgetCallModel::getAccountList() , SIGNAL(accountListUpdated())                  , this                                  , SLOT(updateStatusMessage()                      ));
78
 
   /**/connect(TreeWidgetCallModel::getAccountList() , SIGNAL(accountListUpdated())                  , this                                  , SLOT(updateWindowCallState()                    ));
79
 
   /**/connect(&configurationManager                 , SIGNAL(accountsChanged())                     , TreeWidgetCallModel::getAccountList() , SLOT(updateAccounts()                           ));
80
 
   /*                                                                                                                                                                                           */
81
 
 
82
 
   TreeWidgetCallModel::getAccountList()->updateAccounts();
83
 
}
84
 
 
85
 
///Destructor
86
 
SFLPhoneView::~SFLPhoneView()
87
 
{
88
 
}
89
 
 
90
 
///Init main window
91
 
void SFLPhoneView::loadWindow()
92
 
{
93
 
   updateWindowCallState ();
94
 
   updateRecordButton    ();
95
 
   updateVolumeButton    ();
96
 
   updateRecordBar       ();
97
 
   updateVolumeBar       ();
98
 
   updateVolumeControls  ();
99
 
   updateDialpad         ();
100
 
   updateStatusMessage   ();
101
 
}
102
 
 
103
 
 
104
 
/*****************************************************************************
105
 
 *                                                                           *
106
 
 *                                  Getters                                  *
107
 
 *                                                                           *
108
 
 ****************************************************************************/
109
 
 
110
 
 
111
 
///Return the error window
112
 
QErrorMessage * SFLPhoneView::getErrorWindow()
113
 
{
114
 
   if (!errorWindow)
115
 
      errorWindow = new QErrorMessage(this);
116
 
   return errorWindow;
117
 
}
118
 
 
119
 
 
120
 
/*****************************************************************************
121
 
 *                                                                           *
122
 
 *                              Keyboard input                               *
123
 
 *                                                                           *
124
 
 ****************************************************************************/
125
 
 
126
 
///Called on keyboard
127
 
void SFLPhoneView::typeString(QString str)
128
 
{
129
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
130
 
 
131
 
   Call* call = callTreeModel->getCurrentItem();
132
 
   callManager.playDTMF(str);
133
 
   Call *currentCall = 0;
134
 
   Call *candidate = 0;
135
 
 
136
 
   if(call) {
137
 
      if(call->getState() == CALL_STATE_CURRENT) {
138
 
         currentCall = call;
139
 
      }
140
 
   }
141
 
 
142
 
   foreach (Call* call2, SFLPhone::model()->getCallList()) {
143
 
      if(currentCall != call2 && call2->getState() == CALL_STATE_CURRENT) {
144
 
         action(call2, CALL_ACTION_HOLD);
145
 
      }
146
 
      else if(call2->getState() == CALL_STATE_DIALING) {
147
 
         candidate = call2;
148
 
      }
149
 
   }
150
 
 
151
 
   if(!currentCall && !candidate) {
152
 
      kDebug() << "Typing when no item is selected. Opening an item.";
153
 
      candidate = SFLPhone::model()->addDialingCall();
154
 
   }
155
 
 
156
 
   if(!currentCall && candidate) {
157
 
      candidate->appendText(str);
158
 
   }
159
 
}
160
 
 
161
 
///Called when a backspace is detected
162
 
void SFLPhoneView::backspace()
163
 
{
164
 
   kDebug() << "backspace";
165
 
   Call* call = callTreeModel->getCurrentItem();
166
 
   if(!call) {
167
 
      kDebug() << "Error : Backspace on unexisting call.";
168
 
   }
169
 
   else {
170
 
      call->backspaceItemText();
171
 
      if(call->getState() == CALL_STATE_OVER) {
172
 
         if (callTreeModel->getCurrentItem())
173
 
            callTreeModel->removeItem(callTreeModel->getCurrentItem());
174
 
      }
175
 
   }
176
 
}
177
 
 
178
 
///Called when escape is detected
179
 
void SFLPhoneView::escape()
180
 
{
181
 
   kDebug() << "escape";
182
 
   Call* call = callTreeModel->getCurrentItem();
183
 
   if (callTreeModel->haveOverlay()) {
184
 
      callTreeModel->hideOverlay();
185
 
   }
186
 
   else if(!call) {
187
 
      kDebug() << "Escape when no item is selected. Doing nothing.";
188
 
   }
189
 
   else {
190
 
      if(call->getState() == CALL_STATE_TRANSFER || call->getState() == CALL_STATE_TRANSF_HOLD) {
191
 
         action(call, CALL_ACTION_TRANSFER);
192
 
      }
193
 
      else {
194
 
         action(call, CALL_ACTION_REFUSE);
195
 
      }
196
 
   }
197
 
}
198
 
 
199
 
///Called when enter is detected
200
 
void SFLPhoneView::enter()
201
 
{
202
 
   kDebug() << "enter";
203
 
   Call* call = callTreeModel->getCurrentItem();
204
 
   if(!call) {
205
 
      kDebug() << "Error : Enter on unexisting call.";
206
 
   }
207
 
   else {
208
 
      int state = call->getState();
209
 
      if(state == CALL_STATE_INCOMING || state == CALL_STATE_DIALING || state == CALL_STATE_TRANSFER || state == CALL_STATE_TRANSF_HOLD) {
210
 
         action(call, CALL_ACTION_ACCEPT);
211
 
      }
212
 
      else {
213
 
         kDebug() << "Enter when call selected not in appropriate state. Doing nothing.";
214
 
      }
215
 
   }
216
 
}
217
 
 
218
 
 
219
 
/*****************************************************************************
220
 
 *                                                                           *
221
 
 *                                  Mutator                                  *
222
 
 *                                                                           *
223
 
 ****************************************************************************/
224
 
 
225
 
///
226
 
void SFLPhoneView::action(Call* call, call_action action)
227
 
{
228
 
   if(! call) {
229
 
      kDebug() << "Error : action " << action << "applied on null object call. Should not happen.";
230
 
   }
231
 
   else {
232
 
      try {
233
 
         call->actionPerformed(action);
234
 
      }
235
 
      catch(const char * msg) {
236
 
         getErrorWindow()->showMessage(QString(msg));
237
 
      }
238
 
      updateWindowCallState();
239
 
   }
240
 
}
241
 
 
242
 
 
243
 
/*****************************************************************************
244
 
 *                                                                           *
245
 
 *                       Update display related code                         *
246
 
 *                                                                           *
247
 
 ****************************************************************************/
248
 
 
249
 
 
250
 
///Change GUI icons
251
 
void SFLPhoneView::updateWindowCallState()
252
 
{
253
 
   kDebug() << "Call state changed";
254
 
   bool enabledActions[6]= {true,true,true,true,true,true};
255
 
   QString buttonIconFiles[6] = {ICON_CALL, ICON_HANGUP, ICON_HOLD, ICON_TRANSFER, ICON_REC_DEL_OFF, ICON_MAILBOX};
256
 
   QString actionTexts[6] = {ACTION_LABEL_CALL, ACTION_LABEL_HANG_UP, ACTION_LABEL_HOLD, ACTION_LABEL_TRANSFER, ACTION_LABEL_RECORD, ACTION_LABEL_MAILBOX};
257
 
 
258
 
   Call* call = 0;
259
 
 
260
 
   bool transfer = false;
261
 
   bool recordActivated = false;    //tells whether the call is in recording position
262
 
 
263
 
   enabledActions[SFLPhone::Mailbox] = SFLPhone::model()->getCurrentAccount() && ! SFLPhone::model()->getCurrentAccount()->getAccountDetail(ACCOUNT_MAILBOX).isEmpty();
264
 
 
265
 
   call = callTreeModel->getCurrentItem();
266
 
   if (!call) {
267
 
      kDebug() << "No item selected.";
268
 
      enabledActions[ SFLPhone::Refuse   ] = false;
269
 
      enabledActions[ SFLPhone::Hold     ] = false;
270
 
      enabledActions[ SFLPhone::Transfer ] = false;
271
 
      enabledActions[ SFLPhone::Record   ] = false;
272
 
   }
273
 
   else {
274
 
      call_state state = call->getState();
275
 
      recordActivated = call->getRecording();
276
 
 
277
 
      kDebug() << "Reached  State" << state << " with call" << call->getCallId();
278
 
 
279
 
      switch (state) {
280
 
         case CALL_STATE_INCOMING:
281
 
            buttonIconFiles [ SFLPhone::Accept   ] = ICON_ACCEPT                 ;
282
 
            buttonIconFiles [ SFLPhone::Refuse   ] = ICON_REFUSE                 ;
283
 
            actionTexts     [ SFLPhone::Accept   ] = ACTION_LABEL_ACCEPT         ;
284
 
            actionTexts     [ SFLPhone::Refuse   ] = ACTION_LABEL_REFUSE         ;
285
 
            break;
286
 
         case CALL_STATE_RINGING:
287
 
            enabledActions  [ SFLPhone::Hold     ] = false                       ;
288
 
            enabledActions  [ SFLPhone::Transfer ] = false                       ;
289
 
            break;
290
 
         case CALL_STATE_CURRENT:
291
 
            buttonIconFiles [ SFLPhone::Record   ] = ICON_REC_DEL_ON             ;
292
 
            break;
293
 
         case CALL_STATE_DIALING:
294
 
            enabledActions  [ SFLPhone::Hold     ] = false                       ;
295
 
            enabledActions  [ SFLPhone::Transfer ] = false                       ;
296
 
            enabledActions  [ SFLPhone::Record   ] = false                       ;
297
 
            actionTexts     [ SFLPhone::Accept   ] = ACTION_LABEL_ACCEPT         ;
298
 
            buttonIconFiles [ SFLPhone::Accept   ] = ICON_ACCEPT                 ;
299
 
            break;
300
 
         case CALL_STATE_HOLD:
301
 
            buttonIconFiles [ SFLPhone::Hold     ] = ICON_UNHOLD                 ;
302
 
            actionTexts     [ SFLPhone::Hold     ] = ACTION_LABEL_UNHOLD         ;
303
 
            break;
304
 
         case CALL_STATE_FAILURE:
305
 
            enabledActions  [ SFLPhone::Accept   ] = false                       ;
306
 
            enabledActions  [ SFLPhone::Hold     ] = false                       ;
307
 
            enabledActions  [ SFLPhone::Transfer ] = false                       ;
308
 
            enabledActions  [ SFLPhone::Record   ] = false                       ;
309
 
            break;
310
 
         case CALL_STATE_BUSY:
311
 
            enabledActions  [ SFLPhone::Accept   ] = false                       ;
312
 
            enabledActions  [ SFLPhone::Hold     ] = false                       ;
313
 
            enabledActions  [ SFLPhone::Transfer ] = false                       ;
314
 
            enabledActions  [ SFLPhone::Record   ] = false                       ;
315
 
            break;
316
 
         case CALL_STATE_TRANSFER:
317
 
            buttonIconFiles [ SFLPhone::Accept   ] = ICON_EXEC_TRANSF            ;
318
 
            actionTexts     [ SFLPhone::Transfer ] = ACTION_LABEL_GIVE_UP_TRANSF ;
319
 
            buttonIconFiles [ SFLPhone::Record   ] = ICON_REC_DEL_ON             ;
320
 
            transfer = true;
321
 
            break;
322
 
         case CALL_STATE_TRANSF_HOLD:
323
 
            buttonIconFiles [ SFLPhone::Accept   ] = ICON_EXEC_TRANSF            ;
324
 
            buttonIconFiles [ SFLPhone::Hold     ] = ICON_UNHOLD                 ;
325
 
            actionTexts     [ SFLPhone::Transfer ] = ACTION_LABEL_GIVE_UP_TRANSF ;
326
 
            actionTexts     [ SFLPhone::Hold     ] = ACTION_LABEL_UNHOLD         ;
327
 
            transfer = true;
328
 
            break;
329
 
         case CALL_STATE_OVER:
330
 
            kDebug() << "Error : Reached CALL_STATE_OVER with call "  << call->getCallId() << "!";
331
 
            break;
332
 
         case CALL_STATE_ERROR:
333
 
            kDebug() << "Error : Reached CALL_STATE_ERROR with call " << call->getCallId() << "!";
334
 
            break;
335
 
         default:
336
 
            kDebug() << "Error : Reached unexisting state for call "  << call->getCallId() << "!";
337
 
            break;
338
 
      }
339
 
   }
340
 
 
341
 
   kDebug() << "Updating Window.";
342
 
 
343
 
   emit enabledActionsChangeAsked     ( enabledActions  );
344
 
   emit actionIconsChangeAsked        ( buttonIconFiles );
345
 
   emit actionTextsChangeAsked        ( actionTexts     );
346
 
   emit transferCheckStateChangeAsked ( transfer        );
347
 
   emit recordCheckStateChangeAsked   ( recordActivated );
348
 
 
349
 
   kDebug() << "Window updated.";
350
 
}
351
 
 
352
 
///Deprecated?
353
 
int SFLPhoneView::phoneNumberTypesDisplayed()
354
 
{
355
 
   ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
356
 
   MapStringInt addressBookSettings = configurationManager.getAddressbookSettings().value();
357
 
   int typesDisplayed = 0;
358
 
   if(addressBookSettings[ADDRESSBOOK_DISPLAY_BUSINESS]) {
359
 
      typesDisplayed = typesDisplayed | KABC::PhoneNumber::Work;
360
 
   }
361
 
 
362
 
   if(addressBookSettings[ADDRESSBOOK_DISPLAY_MOBILE]) {
363
 
      typesDisplayed = typesDisplayed | KABC::PhoneNumber::Cell;
364
 
   }
365
 
 
366
 
   if(addressBookSettings[ADDRESSBOOK_DISPLAY_HOME]) {
367
 
      typesDisplayed = typesDisplayed | KABC::PhoneNumber::Home;
368
 
   }
369
 
 
370
 
   return typesDisplayed;
371
 
}
372
 
 
373
 
///Change icon of the record button
374
 
void SFLPhoneView::updateRecordButton()
375
 
{
376
 
   kDebug() << "updateRecordButton";
377
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
378
 
   double recVol = callManager.getVolume(RECORD_DEVICE);
379
 
   if(recVol == 0.00) {
380
 
      toolButton_recVol->setIcon(QIcon(ICON_REC_VOL_0));
381
 
   }
382
 
   else if(recVol < 0.33) {
383
 
      toolButton_recVol->setIcon(QIcon(ICON_REC_VOL_1));
384
 
   }
385
 
   else if(recVol < 0.67) {
386
 
      toolButton_recVol->setIcon(QIcon(ICON_REC_VOL_2));
387
 
   }
388
 
   else {
389
 
      toolButton_recVol->setIcon(QIcon(ICON_REC_VOL_3));
390
 
   }
391
 
 
392
 
   if(recVol > 0) {
393
 
      toolButton_recVol->setChecked(false);
394
 
   }
395
 
}
396
 
 
397
 
///Update the colume button icon
398
 
void SFLPhoneView::updateVolumeButton()
399
 
{
400
 
   kDebug() << "updateVolumeButton";
401
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
402
 
   double sndVol = callManager.getVolume(SOUND_DEVICE);
403
 
 
404
 
   if(sndVol == 0.00) {
405
 
      toolButton_sndVol->setIcon(QIcon(ICON_SND_VOL_0));
406
 
   }
407
 
   else if(sndVol < 0.33) {
408
 
      toolButton_sndVol->setIcon(QIcon(ICON_SND_VOL_1));
409
 
   }
410
 
   else if(sndVol < 0.67) {
411
 
      toolButton_sndVol->setIcon(QIcon(ICON_SND_VOL_2));
412
 
   }
413
 
   else {
414
 
      toolButton_sndVol->setIcon(QIcon(ICON_SND_VOL_3));
415
 
   }
416
 
 
417
 
   if(sndVol > 0) {
418
 
      toolButton_sndVol->setChecked(false);
419
 
   }
420
 
}
421
 
 
422
 
///Update the record bar
423
 
void SFLPhoneView::updateRecordBar(double _value)
424
 
{
425
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
426
 
   double recVol = callManager.getVolume(RECORD_DEVICE);
427
 
   kDebug() << "updateRecordBar" << recVol;
428
 
   int value = (_value > 0)?_value:(int)(recVol * 100);
429
 
   slider_recVol->setValue(value);
430
 
}
431
 
void SFLPhoneView::updateVolumeBar(double _value)
432
 
{
433
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
434
 
   double sndVol = callManager.getVolume(SOUND_DEVICE);
435
 
   kDebug() << "updateVolumeBar" << sndVol;
436
 
   int value = (_value > 0)?_value:(int)(sndVol * 100);
437
 
   slider_sndVol->setValue(value);
438
 
}
439
 
 
440
 
///Hide or show the volume control
441
 
void SFLPhoneView::updateVolumeControls()
442
 
{
443
 
   //SFLPhone::app()->action_displayVolumeControls->setChecked(display);
444
 
   //widget_recVol->setVisible(display);
445
 
   //widget_sndVol->setVisible(display);
446
 
   toolButton_recVol->setVisible ( SFLPhone::app()->action_displayVolumeControls->isChecked()  && ConfigurationSkeleton::displayVolume() );
447
 
   toolButton_sndVol->setVisible ( SFLPhone::app()->action_displayVolumeControls->isChecked()  && ConfigurationSkeleton::displayVolume() );
448
 
   slider_recVol->setVisible     ( SFLPhone::app()->action_displayVolumeControls->isChecked()  && ConfigurationSkeleton::displayVolume() );
449
 
   slider_sndVol->setVisible     ( SFLPhone::app()->action_displayVolumeControls->isChecked()  && ConfigurationSkeleton::displayVolume() );
450
 
 
451
 
}
452
 
 
453
 
///Hide or show the dialpad
454
 
void SFLPhoneView::updateDialpad()
455
 
{
456
 
   widget_dialpad->setVisible(ConfigurationSkeleton::displayDialpad());//TODO use display variable
457
 
}
458
 
 
459
 
///Change the statusbar message
460
 
void SFLPhoneView::updateStatusMessage()
461
 
{
462
 
   Account * account = SFLPhone::model()->getCurrentAccount();
463
 
 
464
 
   if(account == NULL) {
465
 
      emit statusMessageChangeAsked(i18n("No registered accounts"));
466
 
   }
467
 
   else {
468
 
      emit statusMessageChangeAsked(i18n("Using account")
469
 
                     + " \'" + account->getAlias()
470
 
                     + "\' (" + account->getAccountDetail(ACCOUNT_TYPE) + ")") ;
471
 
   }
472
 
}
473
 
 
474
 
 
475
 
/*****************************************************************************
476
 
 *                                                                           *
477
 
 *                                    Slots                                  *
478
 
 *                                                                           *
479
 
 ****************************************************************************/
480
 
 
481
 
///Proxy to hide or show the volume control
482
 
///@TODO is it still needed? <elepage 2011>
483
 
void SFLPhoneView::displayVolumeControls(bool checked)
484
 
{
485
 
   //ConfigurationManagerInterface & configurationManager = ConfigurationManagerInterfaceSingleton::getInstance();
486
 
   ConfigurationSkeleton::setDisplayVolume(checked);
487
 
   updateVolumeControls();
488
 
}
489
 
 
490
 
///Proxy to hide or show the dialpad
491
 
///@TODO is it still needed? <elepage 2011>
492
 
void SFLPhoneView::displayDialpad(bool checked)
493
 
{
494
 
   ConfigurationSkeleton::setDisplayDialpad(checked);
495
 
   updateDialpad();
496
 
}
497
 
 
498
 
///Input grabber
499
 
void SFLPhoneView::on_widget_dialpad_typed(QString text)
500
 
{
501
 
   typeString(text);
502
 
}
503
 
 
504
 
///The value on the slider changed
505
 
void SFLPhoneView::on_slider_recVol_valueChanged(int value)
506
 
{
507
 
   kDebug() << "on_slider_recVol_valueChanged(" << value << ")";
508
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
509
 
   callManager.setVolume(RECORD_DEVICE, (double)value / 100.0);
510
 
   updateRecordButton();
511
 
}
512
 
 
513
 
///The value on the slider changed
514
 
void SFLPhoneView::on_slider_sndVol_valueChanged(int value)
515
 
{
516
 
   kDebug() << "on_slider_sndVol_valueChanged(" << value << ")";
517
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
518
 
   callManager.setVolume(SOUND_DEVICE, (double)value / 100.0);
519
 
   updateVolumeButton();
520
 
}
521
 
 
522
 
///The mute button have been clicked
523
 
void SFLPhoneView::on_toolButton_recVol_clicked(bool checked)
524
 
{
525
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
526
 
   kDebug() << "on_toolButton_recVol_clicked().";
527
 
   if(!checked) {
528
 
      toolButton_recVol->setChecked(false);
529
 
      slider_recVol->setEnabled(true);
530
 
      callManager.setVolume(RECORD_DEVICE, (double)slider_recVol->value() / 100.0);
531
 
   }
532
 
   else {
533
 
      toolButton_recVol->setChecked(true);
534
 
      slider_recVol->setEnabled(false);
535
 
      callManager.setVolume(RECORD_DEVICE, 0.0);
536
 
   }
537
 
   updateRecordButton();
538
 
}
539
 
 
540
 
///The mute button have been clicked
541
 
void SFLPhoneView::on_toolButton_sndVol_clicked(bool checked)
542
 
{
543
 
   CallManagerInterface & callManager = CallManagerInterfaceSingleton::getInstance();
544
 
   kDebug() << "on_toolButton_sndVol_clicked().";
545
 
   if(!checked) {
546
 
      toolButton_sndVol->setChecked(false);
547
 
      slider_sndVol->setEnabled(true);
548
 
      callManager.setVolume(SOUND_DEVICE, (double)slider_sndVol->value() / 100.0);
549
 
   }
550
 
   else {
551
 
      toolButton_sndVol->setChecked(true);
552
 
      slider_sndVol->setEnabled(false);
553
 
      callManager.setVolume(SOUND_DEVICE, 0.0);
554
 
   }
555
 
 
556
 
   updateVolumeButton();
557
 
}
558
 
 
559
 
///There is a right click menu request
560
 
void SFLPhoneView::contextMenuEvent(QContextMenuEvent *event)
561
 
{
562
 
   KMenu menu(this);
563
 
 
564
 
   SFLPhone * window = SFLPhone::app();
565
 
   QList<QAction *> callActions = window->getCallActions();
566
 
 
567
 
   menu.addAction ( callActions.at((int) SFLPhone::Accept) );
568
 
   menu.addAction ( callActions[ SFLPhone::Refuse   ]      );
569
 
   menu.addAction ( callActions[ SFLPhone::Hold     ]      );
570
 
   menu.addAction ( callActions[ SFLPhone::Transfer ]      );
571
 
   menu.addAction ( callActions[ SFLPhone::Record   ]      );
572
 
   menu.addSeparator();
573
 
 
574
 
   QAction* action = new ActionSetAccountFirst(NULL, &menu);
575
 
   action->setChecked(SFLPhone::model()->getPriorAccoundId().isEmpty());
576
 
   connect(action,  SIGNAL(setFirst(Account *)), this  ,  SLOT(setAccountFirst(Account *)));
577
 
   menu.addAction(action);
578
 
 
579
 
   QVector<Account *> accounts = SFLPhone::model()->getAccountList()->registeredAccounts();
580
 
   for (int i = 0 ; i < accounts.size() ; i++) {
581
 
      Account* account = accounts.at(i);
582
 
      QAction* action = new ActionSetAccountFirst(account, &menu);
583
 
      action->setChecked(account->getAccountId() == SFLPhone::model()->getPriorAccoundId());
584
 
      connect(action, SIGNAL(setFirst(Account *)), this  , SLOT(setAccountFirst(Account *)));
585
 
      menu.addAction(action);
586
 
   }
587
 
   menu.exec(event->globalPos());
588
 
}
589
 
 
590
 
///
591
 
void SFLPhoneView::editBeforeCall()
592
 
{
593
 
   QString name;
594
 
   QString number;
595
 
 
596
 
   bool ok;
597
 
   QString newNumber = QInputDialog::getText(this, i18n("Edit before call"), QString(), QLineEdit::Normal, number, &ok);
598
 
   if(ok) {
599
 
      Call* call = SFLPhone::model()->addDialingCall(name);
600
 
      call->appendText(newNumber);
601
 
      //callTreeModel->selectItem(addCallToCallList(call));
602
 
      action(call, CALL_ACTION_ACCEPT);
603
 
   }
604
 
}
605
 
 
606
 
///Pick the default account and load it
607
 
void SFLPhoneView::setAccountFirst(Account * account)
608
 
{
609
 
   kDebug() << "setAccountFirst : " << (account ? account->getAlias() : QString()) << (account ? account->getAccountId() : QString());
610
 
   if(account) {
611
 
      SFLPhone::model()->setPriorAccountId(account->getAccountId());
612
 
   }
613
 
   else {
614
 
      SFLPhone::model()->setPriorAccountId(QString());
615
 
   }
616
 
   kDebug() << "Current account id" << SFLPhone::model()->getCurrentAccountId();
617
 
   updateStatusMessage();
618
 
}
619
 
 
620
 
///Show the configuration dialog
621
 
void SFLPhoneView::configureSflPhone()
622
 
{
623
 
   ConfigurationDialog* configDialog = new ConfigurationDialog(this);
624
 
   configDialog->setModal(true);
625
 
 
626
 
   connect(configDialog, SIGNAL(changesApplied()),
627
 
           this,         SLOT(loadWindow()));
628
 
 
629
 
   //configDialog->reload();
630
 
   configDialog->show();
631
 
}
632
 
 
633
 
///Show the accoutn creation wizard
634
 
void SFLPhoneView::accountCreationWizard()
635
 
{
636
 
   if (!wizard) {
637
 
      wizard = new AccountWizard(this);
638
 
      wizard->setModal(false);
639
 
   }
640
 
   wizard->show();
641
 
}
642
 
 
643
 
///Call
644
 
void SFLPhoneView::accept()
645
 
{
646
 
   Call* call = callTreeModel->getCurrentItem();
647
 
   if(!call) {
648
 
      kDebug() << "Calling when no item is selected. Opening an item.";
649
 
      SFLPhone::model()->addDialingCall();
650
 
   }
651
 
   else {
652
 
      int state = call->getState();
653
 
      if(state == CALL_STATE_RINGING || state == CALL_STATE_CURRENT || state == CALL_STATE_HOLD || state == CALL_STATE_BUSY)
654
 
      {
655
 
         kDebug() << "Calling when item currently ringing, current, hold or busy. Opening an item.";
656
 
         SFLPhone::model()->addDialingCall();
657
 
      }
658
 
      else {
659
 
         action(call, CALL_ACTION_ACCEPT);
660
 
      }
661
 
   }
662
 
}
663
 
 
664
 
///Refuse call
665
 
void SFLPhoneView::refuse()
666
 
{
667
 
   Call* call = callTreeModel->getCurrentItem();
668
 
   if(!call) {
669
 
      kDebug() << "Error : Hanging up when no item selected. Should not happen.";
670
 
   }
671
 
   else {
672
 
      action(call, CALL_ACTION_REFUSE);
673
 
   }
674
 
}
675
 
 
676
 
///Put call on hold
677
 
void SFLPhoneView::hold()
678
 
{
679
 
   Call* call = callTreeModel->getCurrentItem();
680
 
   if(!call) {
681
 
      kDebug() << "Error : Holding when no item selected. Should not happen.";
682
 
   }
683
 
   else {
684
 
      action(call, CALL_ACTION_HOLD);
685
 
   }
686
 
}
687
 
 
688
 
///Transfer a call
689
 
void SFLPhoneView::transfer()
690
 
{
691
 
   Call* call = callTreeModel->getCurrentItem();
692
 
   if(!call) {
693
 
      kDebug() << "Error : Transferring when no item selected. Should not happen.";
694
 
   }
695
 
   else {
696
 
      action(call, CALL_ACTION_TRANSFER);
697
 
   }
698
 
}
699
 
 
700
 
///Record a call
701
 
void SFLPhoneView::record()
702
 
{
703
 
   Call* call = callTreeModel->getCurrentItem();
704
 
   if(!call) {
705
 
      kDebug() << "Error : Recording when no item selected. Should not happen.";
706
 
   }
707
 
   else {
708
 
      action(call, CALL_ACTION_RECORD);
709
 
   }
710
 
}
711
 
 
712
 
///Access the voice mail list
713
 
void SFLPhoneView::mailBox()
714
 
{
715
 
   Account* account = SFLPhone::model()->getCurrentAccount();
716
 
   QString mailBoxNumber = account->getAccountDetail(ACCOUNT_MAILBOX);
717
 
   Call* call = SFLPhone::model()->addDialingCall();
718
 
   call->appendText(mailBoxNumber);
719
 
   action(call, CALL_ACTION_ACCEPT);
720
 
}
721
 
 
722
 
///Called the there is an error (dbus)
723
 
void SFLPhoneView::on1_error(MapStringString details)
724
 
{
725
 
   kDebug() << "Signal : Daemon error : " << details;
726
 
}
727
 
 
728
 
///When a call is comming (dbus)
729
 
void SFLPhoneView::on1_incomingCall(Call* call)
730
 
{
731
 
   kDebug() << "Signal : Incoming Call ! ID = " << call->getCallId();
732
 
 
733
 
   updateWindowCallState();
734
 
 
735
 
   SFLPhone::app()->activateWindow  (      );
736
 
   SFLPhone::app()->raise           (      );
737
 
   SFLPhone::app()->setVisible      ( true );
738
 
 
739
 
   emit incomingCall(call);
740
 
}
741
 
 
742
 
///When a new voice mail is comming
743
 
void SFLPhoneView::on1_voiceMailNotify(const QString &accountID, int count)
744
 
{
745
 
   kDebug() << "Signal : VoiceMail Notify ! " << count << " new voice mails for account " << accountID;
746
 
}
747
 
 
748
 
///When the volume change
749
 
void SFLPhoneView::on1_volumeChanged(const QString & /*device*/, double value)
750
 
{
751
 
   kDebug() << "Signal : Volume Changed !" << value;
752
 
   if(! (toolButton_recVol->isChecked() && value == 0.0))
753
 
      updateRecordBar(value);
754
 
   if(! (toolButton_sndVol->isChecked() && value == 0.0))
755
 
      updateVolumeBar(value);
756
 
}
757
 
 
758
 
#include "SFLPhoneView.moc"