~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to kde/src/sflphone.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/************************************** ************************************
2
 
 *   Copyright (C) 2009-2013 by Savoir-Faire Linux                         *
 
2
 *   Copyright (C) 2009-2014 by Savoir-Faire Linux                         *
3
3
 *   Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com>         *
4
4
 *            Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>*
5
5
 *                                                                         *
41
41
#include <KComboBox>
42
42
#include <KMessageBox>
43
43
#include <KStandardDirs>
 
44
#include <KLocale>
44
45
#include <KEditToolBar>
 
46
#include <KIcon>
45
47
 
46
48
//sflphone library
47
49
#include "lib/sflphone_const.h"
48
 
#include "lib/instance_interface_singleton.h"
49
 
#include "lib/configurationmanager_interface_singleton.h"
 
50
#include "lib/dbus/instancemanager.h"
 
51
#include "lib/dbus/configurationmanager.h"
50
52
#include "lib/contact.h"
51
 
#include "lib/accountlist.h"
 
53
#include "lib/accountlistmodel.h"
52
54
#include "lib/instantmessagingmodel.h"
 
55
#include "lib/numbercategorymodel.h"
 
56
#include "lib/visitors/numbercategoryvisitor.h"
53
57
#include "klib/macromodel.h"
 
58
#include "klib/akonadibackend.h"
 
59
#include "klib/kcfg_settings.h"
 
60
#include "lib/presencestatusmodel.h"
 
61
#include "lib/videomodel.h"
 
62
#include "lib/phonenumber.h"
54
63
 
55
64
//sflphone
56
 
#include "klib/akonadibackend.h"
57
65
#include "accountwizard.h"
58
66
#include "sflphoneview.h"
 
67
#include "actioncollection.h"
59
68
#include "widgets/sflphonetray.h"
60
69
#include "widgets/contactdock.h"
61
70
#include "widgets/historydock.h"
62
71
#include "widgets/bookmarkdock.h"
63
 
#include "widgets/videodock.h"
64
 
#include "klib/configurationskeleton.h"
 
72
#include "widgets/presence.h"
65
73
#include "sflphoneaccessibility.h"
66
 
#include "lib/videomodel.h"
67
74
#include "extendedaction.h"
68
75
#include "errormessage.h"
69
 
 
70
 
SFLPhone* SFLPhone::m_sApp              = nullptr;
71
 
TreeWidgetCallModel* SFLPhone::m_pModel = nullptr;
 
76
#ifdef ENABLE_VIDEO
 
77
#include "widgets/videodock.h"
 
78
#endif
 
79
 
 
80
SFLPhone* SFLPhone::m_sApp = nullptr;
 
81
 
 
82
class ConcreteNumberCategoryVisitor :public NumberCategoryVisitor {
 
83
   void serialize(NumberCategoryModel* model)
 
84
   {
 
85
      Q_UNUSED(model)
 
86
      QList<int> list;
 
87
      for(int i=0;i<model->rowCount();i++) {
 
88
         const QModelIndex& idx = model->index(i,0);
 
89
         if (idx.data(Qt::CheckStateRole) == Qt::Checked) {
 
90
            list << idx.data(NumberCategoryModel::Role::INDEX).toInt();
 
91
         }
 
92
      }
 
93
      ConfigurationSkeleton::setPhoneTypeList(list);
 
94
   }
 
95
 
 
96
   void load(NumberCategoryModel* model)
 
97
   {
 
98
      Q_UNUSED(model)
 
99
      QList<int> list = ConfigurationSkeleton::phoneTypeList();
 
100
      const bool isEmpty = !list.size();
 
101
#define IS_ENABLED(name) (list.indexOf(name) != -1) || isEmpty
 
102
#define ICN(name) new QPixmap(KStandardDirs::locate("data" , QString("sflphone-client-kde/mini/%1.png").arg(name)))
 
103
      model->addCategory("Home"     ,ICN("home")     , KABC::PhoneNumber::Home ,IS_ENABLED( KABC::PhoneNumber::Home     ));
 
104
      model->addCategory("Work"     ,ICN("work")     , KABC::PhoneNumber::Work ,IS_ENABLED( KABC::PhoneNumber::Work     ));
 
105
      model->addCategory("Msg"      ,ICN("mail")     , KABC::PhoneNumber::Msg  ,IS_ENABLED( KABC::PhoneNumber::Msg      ));
 
106
      model->addCategory("Pref"     ,ICN("call")     , KABC::PhoneNumber::Pref ,IS_ENABLED( KABC::PhoneNumber::Pref     ));
 
107
      model->addCategory("Voice"    ,ICN("video")    , KABC::PhoneNumber::Voice,IS_ENABLED( KABC::PhoneNumber::Voice    ));
 
108
      model->addCategory("Fax"      ,ICN("call")     , KABC::PhoneNumber::Fax  ,IS_ENABLED( KABC::PhoneNumber::Fax      ));
 
109
      model->addCategory("Cell"     ,ICN("mobile")   , KABC::PhoneNumber::Cell ,IS_ENABLED( KABC::PhoneNumber::Cell     ));
 
110
      model->addCategory("Video"    ,ICN("call")     , KABC::PhoneNumber::Video,IS_ENABLED( KABC::PhoneNumber::Video    ));
 
111
      model->addCategory("Bbs"      ,ICN("call")     , KABC::PhoneNumber::Bbs  ,IS_ENABLED( KABC::PhoneNumber::Bbs      ));
 
112
      model->addCategory("Modem"    ,ICN("call")     , KABC::PhoneNumber::Modem,IS_ENABLED( KABC::PhoneNumber::Modem    ));
 
113
      model->addCategory("Car"      ,ICN("car")      , KABC::PhoneNumber::Car  ,IS_ENABLED( KABC::PhoneNumber::Car      ));
 
114
      model->addCategory("Isdn"     ,ICN("call")     , KABC::PhoneNumber::Isdn ,IS_ENABLED( KABC::PhoneNumber::Isdn     ));
 
115
      model->addCategory("Pcs"      ,ICN("call")     , KABC::PhoneNumber::Pcs  ,IS_ENABLED( KABC::PhoneNumber::Pcs      ));
 
116
      model->addCategory("Pager"    ,ICN("pager")    , KABC::PhoneNumber::Pager,IS_ENABLED( KABC::PhoneNumber::Pager    ));
 
117
      model->addCategory("Preferred",ICN("preferred"), 10000                   ,IS_ENABLED( 10000                       ));
 
118
#undef ICN
 
119
#undef IS_ENABLED
 
120
   }
 
121
 
 
122
//    QVariant icon(QPixmap* icon )
 
123
//    {
 
124
//       return QIcon(*icon);
 
125
//    }
 
126
};
72
127
 
73
128
///Constructor
74
129
SFLPhone::SFLPhone(QWidget *parent)
75
 
    : KXmlGuiWindow(parent), m_pInitialized(false)
 
130
   : KXmlGuiWindow(parent), m_pInitialized(false)
76
131
#ifdef ENABLE_VIDEO
77
132
      ,m_pVideoDW(nullptr)
78
133
#endif
79
134
{
80
 
    if (!InstanceInterfaceSingleton::getInstance().connection().isConnected() || !InstanceInterfaceSingleton::getInstance().isValid()) {
81
 
       QTimer::singleShot(5000,this,SLOT(timeout()));
82
 
    }
 
135
   if (!DBus::InstanceManager::instance().connection().isConnected() || !DBus::InstanceManager::instance().isValid()) {
 
136
      QTimer::singleShot(5000,this,SLOT(timeout()));
 
137
   }
 
138
   static bool init = false;
 
139
   if (!init) {
 
140
      Call::setContactBackend(AkonadiBackend::instance());
 
141
      NumberCategoryModel::instance()->setVisitor(new ConcreteNumberCategoryVisitor());
 
142
      InstantMessagingModelManager::init();
 
143
      AccountListModel::instance()->setDefaultAccount(AccountListModel::instance()->getAccountById(ConfigurationSkeleton::defaultAccountId()));
 
144
      #ifdef ENABLE_VIDEO
 
145
      VideoModel::instance();
 
146
      #endif
 
147
      init = true;
 
148
   }
83
149
 
84
 
    //Belong to setupActions(), but is needed now
 
150
   //Belong to setupActions(), but is needed now
85
151
   m_sApp = this;
86
 
   action_accept   = new ExtendedAction(this);
87
 
   action_refuse   = new ExtendedAction(this);
88
 
   action_hold     = new ExtendedAction(this);
89
 
   action_transfer = new ExtendedAction(this);
90
 
   action_record   = new ExtendedAction(this);
91
 
   action_mute     = new ExtendedAction(this);
92
 
   action_hangup   = new ExtendedAction(this);
93
 
   action_unhold   = new ExtendedAction(this);
94
 
   action_pickup   = new ExtendedAction(this);
95
 
 
96
 
   action_transfer->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/transfer_grayscale.png" ));
97
 
   action_record  ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/record_grayscale.png"   ));
98
 
   action_hold    ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/hold_grayscale.png"     ));
99
 
   action_refuse  ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/refuse_grayscale.png"   ));
100
 
   action_mute    ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/mutemic_grayscale.png"  ));
101
 
   action_hangup  ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/hangup_grayscale.png"   ));
102
 
   action_unhold  ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/unhold_grayscale.png"   ));
103
 
   action_pickup  ->setAltIcon(KStandardDirs::locate("data" , "sflphone-client-kde/pickup_grayscale.png"   ));
104
 
 
105
 
   action_transfer->setText ( i18n( "Transfer" ) );
106
 
   action_record  ->setText ( i18n( "Record"   ) );
107
 
   action_hold    ->setText ( i18n( "Hold"     ) );
108
 
   action_refuse  ->setText ( i18n( "Refuse"   ) );
109
 
   action_hangup  ->setText ( i18n( "Hang up"  ) );
110
 
   action_unhold  ->setText ( i18n( "Unhold"   ) );
111
 
   action_pickup  ->setText ( i18n( "Pickup"   ) );
112
 
   action_mute    ->setText ( i18nc("Mute the current audio device", "Mute"     ) );
113
 
   
114
 
   action_mute->setCheckable(true);
115
152
 
116
153
   m_pView = new SFLPhoneView(this);
117
 
}
118
 
 
119
 
///Destructor
120
 
SFLPhone::~SFLPhone()
121
 
{
122
 
   if (!isHidden()) {
123
 
      ConfigurationSkeleton::setDisplayContactDock ( m_pContactCD->isVisible()  );
124
 
      ConfigurationSkeleton::setDisplayHistoryDock ( m_pHistoryDW->isVisible()  );
125
 
      ConfigurationSkeleton::setDisplayBookmarkDock( m_pBookmarkDW->isVisible() );
126
 
   }
127
 
 
128
 
   delete action_accept                ;
129
 
   delete action_refuse                ;
130
 
   delete action_hold                  ;
131
 
   delete action_transfer              ;
132
 
   delete action_record                ;
133
 
   delete action_mailBox               ;
134
 
   delete action_close                 ;
135
 
   delete action_quit                  ;
136
 
   delete action_displayVolumeControls ;
137
 
   delete action_displayDialpad        ;
138
 
   delete action_displayMessageBox     ;
139
 
   delete action_configureSflPhone     ;
140
 
   delete action_configureShortcut     ;
141
 
   delete action_accountCreationWizard ;
142
 
   delete action_pastenumber           ;
143
 
   delete action_showContactDock       ;
144
 
   delete action_showHistoryDock       ;
145
 
   delete action_showBookmarkDock      ;
146
 
   delete action_editToolBar           ;
147
 
 
148
 
   delete m_pView            ;
149
 
   delete m_pTrayIcon        ;
150
 
   delete m_pStatusBarWidget ;
151
 
   delete m_pContactCD       ;
152
 
   delete m_pCentralDW       ;
153
 
   delete m_pHistoryDW       ;
154
 
   delete m_pBookmarkDW      ;
155
 
 
156
 
   if (m_pModel) {
157
 
      delete m_pModel;
158
 
   }
159
 
   delete AkonadiBackend::getInstance();
160
 
   TreeWidgetCallModel::destroy();
161
 
   //saveState();
162
 
}
163
 
 
164
 
///Init everything
165
 
bool SFLPhone::initialize()
166
 
{
167
 
   if ( m_pInitialized ) {
168
 
      kDebug() << "Already initialized.";
169
 
      return false;
170
 
   }
171
154
 
172
155
   ConfigurationSkeleton::self();
173
156
 
195
178
   m_pCentralDW->setContentsMargins(0,0,0,0);
196
179
   m_pView->setContentsMargins     (0,0,0,0);
197
180
 
198
 
 
199
 
   m_pContactCD = new ContactDock(this);
200
 
 
201
 
   m_pHistoryDW       = new HistoryDock  ( this                     );
202
 
   m_pBookmarkDW      = new BookmarkDock ( this                     );
203
 
   m_pStatusBarWidget = new QLabel       (                          );
 
181
   m_pContactCD       = new ContactDock  ( this );
 
182
   m_pHistoryDW       = new HistoryDock  ( this );
 
183
   m_pBookmarkDW      = new BookmarkDock ( this );
 
184
   m_pStatusBarWidget = new QLabel       ( this );
204
185
 
205
186
   //System tray
206
187
   m_pTrayIcon        = new SFLPhoneTray ( this->windowIcon(), this );
227
208
 
228
209
   m_pCentralDW->show();
229
210
 
230
 
   QList<QTabBar*> tabBars = this->findChildren<QTabBar*>();
231
 
   if(tabBars.count())
232
 
   {
233
 
      foreach(QTabBar* bar, tabBars) {
234
 
         for (int i=0;i<bar->count();i++) {
235
 
            QString text = bar->tabText(i);
236
 
            if (text == i18n("Call")) {
237
 
               bar->setCurrentIndex(i);
238
 
               break;
239
 
            }
240
 
         }
241
 
      }
242
 
   }
 
211
   selectCallTab();
243
212
 
244
213
   setWindowIcon (QIcon(ICON_SFLPHONE) );
245
214
   setWindowTitle(i18n("SFLphone")     );
246
 
   setupActions();
 
215
   ActionCollection::instance()->setupAction();
 
216
   setAutoSaveSettings();
 
217
   createGUI();
247
218
 
248
 
   m_pTrayIcon->addAction( action_accept   );
249
 
   m_pTrayIcon->addAction( action_mailBox  );
250
 
   m_pTrayIcon->addAction( action_refuse   );
251
 
   m_pTrayIcon->addAction( action_hold     );
252
 
   m_pTrayIcon->addAction( action_transfer );
253
 
   m_pTrayIcon->addAction( action_record   );
 
219
   m_pTrayIcon->addAction( ActionCollection::instance()->acceptAction  () );
 
220
   m_pTrayIcon->addAction( ActionCollection::instance()->mailBoxAction () );
 
221
   m_pTrayIcon->addAction( ActionCollection::instance()->refuseAction  () );
 
222
   m_pTrayIcon->addAction( ActionCollection::instance()->holdAction    () );
 
223
   m_pTrayIcon->addAction( ActionCollection::instance()->transferAction() );
 
224
   m_pTrayIcon->addAction( ActionCollection::instance()->recordAction  () );
254
225
   m_pTrayIcon->addSeparator();
255
 
   m_pTrayIcon->addAction( action_quit     );
256
 
 
257
 
   connect(action_showContactDock, SIGNAL(toggled(bool)),m_pContactCD, SLOT(setVisible(bool)));
258
 
   connect(action_showHistoryDock, SIGNAL(toggled(bool)),m_pHistoryDW, SLOT(setVisible(bool)));
259
 
   connect(action_showBookmarkDock,SIGNAL(toggled(bool)),m_pBookmarkDW,SLOT(setVisible(bool)));
260
 
 
261
 
   #ifdef ENABLE_VIDEO
262
 
   connect(VideoModel::getInstance(),SIGNAL(videoCallInitiated(VideoRenderer*)),this,SLOT(displayVideoDock(VideoRenderer*)));
263
 
   #endif
 
226
   m_pTrayIcon->addAction( ActionCollection::instance()->quitAction    () );
 
227
 
 
228
   connect(ActionCollection::instance()->showContactDockAction(), SIGNAL(toggled(bool)),m_pContactCD, SLOT(setVisible(bool)));
 
229
   connect(ActionCollection::instance()->showHistoryDockAction(), SIGNAL(toggled(bool)),m_pHistoryDW, SLOT(setVisible(bool)));
 
230
   connect(ActionCollection::instance()->showBookmarkDockAction(),SIGNAL(toggled(bool)),m_pBookmarkDW,SLOT(setVisible(bool)));
 
231
 
 
232
#ifdef ENABLE_VIDEO
 
233
   connect(VideoModel::instance(),SIGNAL(videoCallInitiated(VideoRenderer*)),this,SLOT(displayVideoDock(VideoRenderer*)));
 
234
#endif
264
235
 
265
236
   statusBar()->addWidget(m_pStatusBarWidget);
266
237
 
267
 
 
268
238
   m_pTrayIcon->show();
269
239
 
270
 
 
271
240
   setObjectNames();
272
241
   QMetaObject::connectSlotsByName(this);
273
242
   m_pView->loadWindow();
274
243
 
275
244
   move(QCursor::pos().x() - geometry().width()/2, QCursor::pos().y() - geometry().height()/2);
276
 
   show();
277
245
 
278
 
   if (AccountList::getInstance()->size() <= 1) {
 
246
   if (AccountListModel::instance()->size() <= 1)
279
247
      (new AccountWizard())->show();
280
 
   }
281
248
 
282
 
   m_pIconChanged = false;
283
249
   m_pInitialized = true ;
284
250
 
285
251
   KStatusBar* bar = statusBar();
286
 
 
287
 
   QLabel* curAccL = new QLabel(i18n("Current account:"));
 
252
   int left,top,right,bottom;
 
253
   bar->layout()->getContentsMargins ( &left, &top, &right, &bottom );
 
254
   bar->layout()->setContentsMargins(0,top,0,bottom);
 
255
 
 
256
   //The presence button act as the label, remove the original one
 
257
   QList<QLabel*> labels = bar->findChildren<QLabel*>();
 
258
   for (int i=0;i<labels.size();i++) {
 
259
      bar->layout()->removeWidget(labels[i]);
 
260
      labels[i]->setHidden(true);
 
261
   }
 
262
 
 
263
   m_pPresent = new QToolButton(bar);
 
264
   m_pPresent->setAutoRaise(true);
 
265
   m_pPresent->setText("Online");
 
266
   m_pPresent->setCheckable(true);
 
267
//    m_pPresent->setStyleSheet("background-color:red;");
 
268
   bar->addWidget(m_pPresent);
 
269
   connect(PresenceStatusModel::instance(),SIGNAL(currentNameChanged(QString)),this,SLOT(updatePresence(QString)));
 
270
   connect(PresenceStatusModel::instance(),SIGNAL(currentNameChanged(QString)),this,SLOT(hidePresenceDock()));
 
271
 
 
272
   m_pPresenceDock = new QDockWidget(this);
 
273
   m_pPresenceDock->setObjectName("presence-dock");
 
274
   m_pPresenceDock->setWidget(new Presence(m_pPresenceDock));
 
275
   m_pPresenceDock->setAllowedAreas(Qt::BottomDockWidgetArea);
 
276
   m_pPresenceDock->setFeatures(QDockWidget::NoDockWidgetFeatures);
 
277
   addDockWidget( Qt::BottomDockWidgetArea, m_pPresenceDock );
 
278
   m_pPresenceDock->setVisible(false);
 
279
   if (m_pPresenceDock->titleBarWidget())
 
280
      m_pPresenceDock->titleBarWidget()->setVisible(false);
 
281
 
 
282
   QLabel* curAccL = new QLabel(i18n("Account:"));
288
283
   bar->addPermanentWidget(curAccL);
289
284
 
290
285
   m_pAccountStatus = new KComboBox(bar);
291
 
   AccountListNoCheckProxyModel* accountModel = new AccountListNoCheckProxyModel();
292
 
   m_pAccountStatus->setModel(accountModel);
 
286
   m_pAccountModel = new AccountListNoCheckProxyModel();
 
287
   m_pAccountStatus->setModel(m_pAccountModel);
293
288
   m_pAccountStatus->setMinimumSize(100,0);
294
289
   bar->addPermanentWidget(m_pAccountStatus);
295
 
   
 
290
   connect(m_pPresent,SIGNAL(toggled(bool)),m_pPresenceDock,SLOT(setVisible(bool)));
 
291
 
296
292
   QToolButton* m_pReloadButton = new QToolButton(this);
297
293
   m_pReloadButton->setIcon(KIcon("view-refresh"));
298
294
   bar->addPermanentWidget(m_pReloadButton);
299
 
   connect(m_pReloadButton,SIGNAL(clicked()),AccountList::getInstance(),SLOT(registerAllAccounts()));
300
 
   
301
 
 
 
295
   connect(m_pReloadButton,SIGNAL(clicked()),AccountListModel::instance(),SLOT(registerAllAccounts()));
302
296
   connect(m_pAccountStatus, SIGNAL(currentIndexChanged(int)), this, SLOT(currentAccountIndexChanged(int)) );
303
 
   connect(AccountList::getInstance(), SIGNAL(priorAccountChanged(Account*)),this,SLOT(currentPriorAccountChanged(Account*)));
 
297
   connect(AccountListModel::instance(), SIGNAL(priorAccountChanged(Account*)),this,SLOT(currentPriorAccountChanged(Account*)));
304
298
 
305
 
   if (!model()->isValid()) {
 
299
   if (!CallModel::instance()->isValid()) {
306
300
      KMessageBox::error(this,i18n("The SFLPhone daemon (sflphoned) is not available. Please be sure it is installed correctly or launch it manually"));
307
301
      QTimer::singleShot(2500,this,SLOT(timeout())); //FIXME this may leave the client in an unreliable state
308
302
      //exit(1); //Don't try to exit normally, it will segfault, the application is already in a broken state if this is reached //BUG break some slow netbooks
309
303
   }
310
304
   try {
311
 
      currentPriorAccountChanged(AccountList::getCurrentAccount());
 
305
      currentPriorAccountChanged(AccountListModel::currentAccount());
312
306
   }
313
307
   catch(const char * msg) {
314
308
      KMessageBox::error(this,msg);
316
310
      //exit(1); //Don't try to exit normally, it will segfault, the application is already in a broken state if this is reached //BUG break some slow netbooks
317
311
   }
318
312
 
319
 
   return true;
320
 
}
 
313
   if (ConfigurationSkeleton::displayOnStart())
 
314
      show();
 
315
   else
 
316
      close();
 
317
} //SFLPhone
321
318
 
322
 
///Setup evry actions
323
 
void SFLPhone::setupActions()
 
319
///Destructor
 
320
SFLPhone::~SFLPhone()
324
321
{
325
 
   kDebug() << "setupActions";
326
 
 
327
 
   action_mailBox  = new KAction(this);
328
 
   action_accept->setShortcut      ( Qt::CTRL + Qt::Key_A );
329
 
   action_refuse->setShortcut      ( Qt::CTRL + Qt::Key_D );
330
 
   action_hold->setShortcut        ( Qt::CTRL + Qt::Key_H );
331
 
   action_transfer->setShortcut    ( Qt::CTRL + Qt::Key_T );
332
 
   action_record->setShortcut      ( Qt::CTRL + Qt::Key_R );
333
 
   action_mailBox->setShortcut     ( Qt::CTRL + Qt::Key_M );
334
 
 
335
 
   action_screen = new QActionGroup(this);
336
 
   action_screen->setExclusive(true);
337
 
 
338
 
   action_close = KStandardAction::close(this, SLOT(close()), this);
339
 
   action_quit  = KStandardAction::quit(this, SLOT(quitButton()), this);
340
 
 
341
 
   action_configureSflPhone = KStandardAction::preferences(m_pView, SLOT(configureSflPhone()), this);
342
 
   action_configureSflPhone->setText(i18n("Configure SFLphone"));
343
 
 
344
 
   action_displayDialpad        = new KAction(KIcon(QIcon(ICON_DISPLAY_DIALPAD)), i18n("Display dialpad")                 , this);
345
 
   action_displayMessageBox     = new KAction(KIcon("mail-message-new"), i18n("Display text message box")                 , this);
346
 
   action_displayVolumeControls = new KAction(KIcon(QIcon(ICON_DISPLAY_VOLUME_CONSTROLS)), i18n("Display volume controls"), this);
347
 
   action_pastenumber           = new KAction(KIcon("edit-paste"), i18n("Paste")                                          , this);
348
 
   action_showContactDock       = new KAction(KIcon("edit-find-user")   , i18n("Display Contact")                         , this);
349
 
   action_showHistoryDock       = new KAction(KIcon("view-history")     , i18n("Display history")                         , this);
350
 
   action_showBookmarkDock      = new KAction(KIcon("bookmark-new-list"), i18n("Display bookmark")                        , this);
351
 
   action_editToolBar           = new KAction(KIcon("configure-toolbars"), i18n("Configure Toolbars")                     , this);
352
 
   action_accountCreationWizard = new KAction(i18n("Account creation wizard")                                             , this);
353
 
 
354
 
   action_displayDialpad->setCheckable( true );
355
 
   action_displayDialpad->setChecked  ( ConfigurationSkeleton::displayDialpad() );
356
 
   action_configureSflPhone->setText(i18n("Configure SFLphone"));
357
 
 
358
 
   action_displayMessageBox->setCheckable( true );
359
 
   action_displayMessageBox->setChecked  ( ConfigurationSkeleton::displayMessageBox() );
360
 
 
361
 
   action_displayVolumeControls->setCheckable( true );
362
 
   action_displayVolumeControls->setChecked  ( ConfigurationSkeleton::displayVolume() );
363
 
 
364
 
   action_pastenumber->setShortcut ( Qt::CTRL + Qt::Key_V );
365
 
 
366
 
   action_showContactDock->setCheckable( true );
367
 
   action_showContactDock->setChecked(ConfigurationSkeleton::displayContactDock());
368
 
 
369
 
   action_showHistoryDock->setCheckable( true );
370
 
   action_showHistoryDock->setChecked(ConfigurationSkeleton::displayHistoryDock());
371
 
 
372
 
   action_showBookmarkDock->setCheckable( true );
373
 
   action_showBookmarkDock->setChecked(ConfigurationSkeleton::displayBookmarkDock());
374
 
 
375
 
 
376
 
 
377
 
   action_configureShortcut = new KAction(KIcon(KIcon("configure-shortcuts")), i18n("Configure Shortcut"), this);
378
 
   //                    SENDER                        SIGNAL               RECEIVER                 SLOT               /
379
 
   /**/connect(action_accept,                SIGNAL(triggered()),           m_pView , SLOT(accept())                    );
380
 
   /**/connect(action_hangup,                SIGNAL(triggered()),           m_pView , SLOT(hangup())                    );
381
 
   /**/connect(action_refuse,                SIGNAL(triggered()),           m_pView , SLOT(refuse())                    );
382
 
   /**/connect(action_hold,                  SIGNAL(triggered()),           m_pView , SLOT(hold())                      );
383
 
   /**/connect(action_unhold,                SIGNAL(triggered()),           m_pView , SLOT(unhold())                    );
384
 
   /**/connect(action_transfer,              SIGNAL(triggered()),           m_pView , SLOT(transfer())                  );
385
 
   /**/connect(action_record,                SIGNAL(triggered()),           m_pView , SLOT(record())                    );
386
 
   /**/connect(action_mute,                  SIGNAL(toggled(bool)),         m_pView , SLOT(mute(bool))                  );
387
 
   /**/connect(action_mailBox,               SIGNAL(triggered()),           m_pView , SLOT(mailBox())                   );
388
 
   /**/connect(action_displayVolumeControls, SIGNAL(toggled(bool)),         m_pView , SLOT(displayVolumeControls(bool)) );
389
 
   /**/connect(action_displayDialpad,        SIGNAL(toggled(bool)),         m_pView , SLOT(displayDialpad(bool))        );
390
 
   /**/connect(action_displayMessageBox,     SIGNAL(toggled(bool)),         m_pView , SLOT(displayMessageBox(bool))     );
391
 
   /**/connect(action_accountCreationWizard, SIGNAL(triggered()),           m_pView , SLOT(accountCreationWizard())     );
392
 
   /**/connect(action_pastenumber,           SIGNAL(triggered()),           m_pView , SLOT(paste())                     );
393
 
   /**/connect(action_configureShortcut,     SIGNAL(triggered()),           this    , SLOT(showShortCutEditor())        );
394
 
   /**/connect(action_editToolBar,           SIGNAL(triggered()),           this    , SLOT(editToolBar())               );
395
 
   /**/connect(MacroModel::getInstance(),    SIGNAL(addAction(KAction*)),   this    , SLOT(addMacro(KAction*))          );
396
 
   /*                                                                                                                   */
397
 
 
398
 
   actionCollection()->addAction("action_accept"                , action_accept                );
399
 
   actionCollection()->addAction("action_refuse"                , action_refuse                );
400
 
   actionCollection()->addAction("action_hold"                  , action_hold                  );
401
 
   actionCollection()->addAction("action_transfer"              , action_transfer              );
402
 
   actionCollection()->addAction("action_record"                , action_record                );
403
 
   actionCollection()->addAction("action_mailBox"               , action_mailBox               );
404
 
   actionCollection()->addAction("action_close"                 , action_close                 );
405
 
   actionCollection()->addAction("action_quit"                  , action_quit                  );
406
 
   actionCollection()->addAction("action_displayVolumeControls" , action_displayVolumeControls );
407
 
   actionCollection()->addAction("action_displayDialpad"        , action_displayDialpad        );
408
 
   actionCollection()->addAction("action_displayMessageBox"     , action_displayMessageBox     );
409
 
   actionCollection()->addAction("action_configureSflPhone"     , action_configureSflPhone     );
410
 
   actionCollection()->addAction("action_accountCreationWizard" , action_accountCreationWizard );
411
 
   actionCollection()->addAction("action_configureShortcut"     , action_configureShortcut     );
412
 
   actionCollection()->addAction("action_pastenumber"           , action_pastenumber           );
413
 
   actionCollection()->addAction("action_showContactDock"       , action_showContactDock       );
414
 
   actionCollection()->addAction("action_showHistoryDock"       , action_showHistoryDock       );
415
 
   actionCollection()->addAction("action_showBookmarkDock"      , action_showBookmarkDock      );
416
 
   actionCollection()->addAction("action_editToolBar"           , action_editToolBar           );
417
 
 
418
 
   MacroModel::getInstance()->initMacros();
419
 
 
420
 
 
421
 
   QList<KAction*> acList = *SFLPhoneAccessibility::getInstance();
422
 
 
423
 
   foreach(KAction* ac,acList) {
424
 
      actionCollection()->addAction(ac->objectName() , ac);
 
322
   if (!isHidden()) {
 
323
      ConfigurationSkeleton::setDisplayContactDock ( m_pContactCD->isVisible()  );
 
324
      ConfigurationSkeleton::setDisplayHistoryDock ( m_pHistoryDW->isVisible()  );
 
325
      ConfigurationSkeleton::setDisplayBookmarkDock( m_pBookmarkDW->isVisible() );
425
326
   }
426
327
 
427
 
   setAutoSaveSettings();
428
 
   createGUI();
 
328
   delete m_pView            ;
 
329
   delete m_pTrayIcon        ;
 
330
   delete m_pStatusBarWidget ;
 
331
   delete m_pContactCD       ;
 
332
   delete m_pCentralDW       ;
 
333
   delete m_pHistoryDW       ;
 
334
   delete m_pBookmarkDW      ;
 
335
   delete m_pAccountModel    ;
 
336
   delete m_pPresent         ;
 
337
   delete m_pPresenceDock    ;
 
338
 
 
339
   delete AkonadiBackend::instance();
 
340
   delete CallModel::instance();
 
341
   //saveState();
 
342
}
 
343
 
 
344
///Init everything
 
345
bool SFLPhone::initialize() //TODO deprecate
 
346
{
 
347
   return !m_pInitialized;
429
348
}
430
349
 
431
350
 
444
363
///Get the view (to be used with the singleton)
445
364
SFLPhoneView* SFLPhone::view()
446
365
{
447
 
   return m_pView;
448
 
}
449
 
 
450
 
///Singleton
451
 
TreeWidgetCallModel* SFLPhone::model()
452
 
{
453
 
   if (!m_pModel) {
454
 
      m_pModel = new TreeWidgetCallModel();
455
 
      m_pModel->initCall();
456
 
      Call::setContactBackend(AkonadiBackend::getInstance());
457
 
      InstantMessagingModelManager::init(m_pModel);
458
 
      AccountList::getInstance()->setDefaultAccount(AccountList::getInstance()->getAccountById(ConfigurationSkeleton::defaultAccountId()));
459
 
      #ifdef ENABLE_VIDEO
460
 
      VideoModel::getInstance();
461
 
      #endif
462
 
    }
463
 
   return m_pModel;
 
366
   return app()->m_pView;
464
367
}
465
368
 
466
369
///Return the contact dock
481
384
   return m_pBookmarkDW;
482
385
}
483
386
 
484
 
void SFLPhone::showShortCutEditor() {
485
 
   KShortcutsDialog::configure( actionCollection() );
486
 
}
487
 
 
488
 
///Produce an actionList for auto CallBack
489
 
QList<QAction*> SFLPhone::getCallActions()
490
 
{
491
 
   QList<QAction*> callActions = QList<QAction *>();
492
 
   callActions.insert((int) Accept   , action_accept   );
493
 
   callActions.insert((int) Refuse   , action_refuse   );
494
 
   callActions.insert((int) Hold     , action_hold     );
495
 
   callActions.insert((int) Transfer , action_transfer );
496
 
   callActions.insert((int) Record   , action_record   );
497
 
   callActions.insert((int) Mailbox  , action_mailBox  );
498
 
   return callActions;
499
 
}
500
 
 
501
 
 
502
387
/*****************************************************************************
503
388
 *                                                                           *
504
389
 *                                  Setters                                  *
544
429
   qApp->quit();
545
430
}
546
431
 
547
 
///Called when something happen
548
 
void SFLPhone::changeEvent(QEvent* event)
549
 
{
550
 
   if (event->type() == QEvent::ActivationChange && m_pIconChanged && isActiveWindow()) {
551
 
      m_pIconChanged = false;
552
 
   }
553
 
}
554
 
 
555
 
///Change status message
556
 
void SFLPhone::on_m_pView_statusMessageChangeAsked(const QString& message)
557
 
{
558
 
   Q_UNUSED(message)
559
 
//    m_pStatusBarWidget->setText(message);
560
 
}
561
 
 
562
432
///Change windowtitle
563
433
void SFLPhone::on_m_pView_windowTitleChangeAsked(const QString& message)
564
434
{
568
438
///Enable or disable toolbar items
569
439
void SFLPhone::on_m_pView_enabledActionsChangeAsked(const bool* enabledActions)
570
440
{
571
 
   action_accept->setVisible   ( enabledActions[SFLPhone::Accept   ]);
572
 
   action_refuse->setVisible   ( enabledActions[SFLPhone::Refuse   ]);
573
 
   action_hold->setVisible     ( enabledActions[SFLPhone::Hold     ]);
574
 
   action_transfer->setVisible ( enabledActions[SFLPhone::Transfer ]);
575
 
   action_record->setVisible   ( enabledActions[SFLPhone::Record   ]);
576
 
   action_mailBox->setVisible  ( enabledActions[SFLPhone::Mailbox  ]);
 
441
   ActionCollection::instance()->acceptAction()->setVisible   ( enabledActions[SFLPhone::CallAction::Accept   ]);
 
442
   ActionCollection::instance()->refuseAction()->setVisible   ( enabledActions[SFLPhone::CallAction::Refuse   ]);
 
443
   ActionCollection::instance()->holdAction()->setVisible     ( enabledActions[SFLPhone::CallAction::Hold     ]);
 
444
   ActionCollection::instance()->transferAction()->setVisible ( enabledActions[SFLPhone::CallAction::Transfer ]);
 
445
   ActionCollection::instance()->recordAction()->setVisible   ( enabledActions[SFLPhone::CallAction::Record   ]);
 
446
   ActionCollection::instance()->mailBoxAction()->setVisible  ( enabledActions[SFLPhone::CallAction::Mailbox  ]);
577
447
}
578
448
 
579
449
///Change icons
580
450
void SFLPhone::on_m_pView_actionIconsChangeAsked(const QString* actionIcons)
581
451
{
582
 
   action_accept->setIcon   ( QIcon(actionIcons[SFLPhone::Accept   ]));
583
 
   action_refuse->setIcon   ( QIcon(actionIcons[SFLPhone::Refuse   ]));
584
 
   action_hold->setIcon     ( QIcon(actionIcons[SFLPhone::Hold     ]));
585
 
   action_transfer->setIcon ( QIcon(actionIcons[SFLPhone::Transfer ]));
586
 
   action_record->setIcon   ( QIcon(actionIcons[SFLPhone::Record   ]));
587
 
   action_mailBox->setIcon  ( QIcon(actionIcons[SFLPhone::Mailbox  ]));
 
452
   ActionCollection::instance()->acceptAction()->setIcon   ( QIcon(actionIcons[SFLPhone::CallAction::Accept   ]));
 
453
   ActionCollection::instance()->refuseAction()->setIcon   ( QIcon(actionIcons[SFLPhone::CallAction::Refuse   ]));
 
454
   ActionCollection::instance()->holdAction()->setIcon     ( QIcon(actionIcons[SFLPhone::CallAction::Hold     ]));
 
455
   ActionCollection::instance()->transferAction()->setIcon ( QIcon(actionIcons[SFLPhone::CallAction::Transfer ]));
 
456
   ActionCollection::instance()->recordAction()->setIcon   ( QIcon(actionIcons[SFLPhone::CallAction::Record   ]));
 
457
   ActionCollection::instance()->mailBoxAction()->setIcon  ( QIcon(actionIcons[SFLPhone::CallAction::Mailbox  ]));
588
458
}
589
459
 
590
460
///Change text
591
461
void SFLPhone::on_m_pView_actionTextsChangeAsked(const QString* actionTexts)
592
462
{
593
 
   action_accept->setText   ( actionTexts[SFLPhone::Accept   ]);
594
 
   action_refuse->setText   ( actionTexts[SFLPhone::Refuse   ]);
595
 
   action_hold->setText     ( actionTexts[SFLPhone::Hold     ]);
596
 
   action_transfer->setText ( actionTexts[SFLPhone::Transfer ]);
597
 
   action_record->setText   ( actionTexts[SFLPhone::Record   ]);
598
 
   action_mailBox->setText  ( actionTexts[SFLPhone::Mailbox  ]);
 
463
   ActionCollection::instance()->acceptAction()->setText   ( actionTexts[SFLPhone::CallAction::Accept   ]);
 
464
   ActionCollection::instance()->refuseAction()->setText   ( actionTexts[SFLPhone::CallAction::Refuse   ]);
 
465
   ActionCollection::instance()->holdAction()->setText     ( actionTexts[SFLPhone::CallAction::Hold     ]);
 
466
   ActionCollection::instance()->transferAction()->setText ( actionTexts[SFLPhone::CallAction::Transfer ]);
 
467
   ActionCollection::instance()->recordAction()->setText   ( actionTexts[SFLPhone::CallAction::Record   ]);
 
468
   ActionCollection::instance()->mailBoxAction()->setText  ( actionTexts[SFLPhone::CallAction::Mailbox  ]);
599
469
}
600
470
 
601
471
///Change transfer state
602
472
void SFLPhone::on_m_pView_transferCheckStateChangeAsked(bool transferCheckState)
603
473
{
604
 
   action_transfer->setChecked(transferCheckState);
 
474
   ActionCollection::instance()->transferAction()->setChecked(transferCheckState);
605
475
}
606
476
 
607
477
///Change record state
608
478
void SFLPhone::on_m_pView_recordCheckStateChangeAsked(bool recordCheckState)
609
479
{
610
 
   action_record->setChecked(recordCheckState);
 
480
   ActionCollection::instance()->recordAction()->setChecked(recordCheckState);
611
481
}
612
482
 
613
483
///Called when a call is coming
614
484
void SFLPhone::on_m_pView_incomingCall(const Call* call)
615
485
{
616
 
   Contact* contact = AkonadiBackend::getInstance()->getContactByPhone(call->getPeerPhoneNumber());
617
 
   if (contact && call) {
618
 
      KNotification::event(KNotification::Notification, i18n("New incoming call"), i18n("New call from:\n%1",call->getPeerName().isEmpty() ? call->getPeerPhoneNumber() : call->getPeerName()),((contact->getPhoto())?*contact->getPhoto():nullptr));
 
486
   if (call) {
 
487
      const Contact* contact = call->peerPhoneNumber()->contact();
 
488
      if (contact)
 
489
         KNotification::event(KNotification::Notification, i18n("New incoming call"), i18n("New call from:\n%1",call->peerName().isEmpty() ? call->peerPhoneNumber()->uri() : call->peerName()),((contact->photo())?*contact->photo():nullptr));
 
490
      else
 
491
         KNotification::event(KNotification::Notification, i18n("New incoming call"), i18n("New call from:\n%1",call->peerName().isEmpty() ? call->peerPhoneNumber()->uri() : call->peerName()));
619
492
   }
620
 
   KNotification::event(KNotification::Notification, i18n("New incoming call"), i18n("New call from:\n%1",call->getPeerName().isEmpty() ? call->getPeerPhoneNumber() : call->getPeerName()));
621
493
}
622
494
 
623
495
///Change current account
624
496
void SFLPhone::currentAccountIndexChanged(int newIndex)
625
497
{
626
 
   if (AccountList::getInstance()->size()) {
627
 
      Account* acc = AccountList::getInstance()->getAccountByModelIndex(AccountList::getInstance()->index(newIndex,0));
 
498
   if (AccountListModel::instance()->size()) {
 
499
      const Account* acc = AccountListModel::instance()->getAccountByModelIndex(AccountListModel::instance()->index(newIndex,0));
628
500
      if (acc)
629
 
         AccountList::getInstance()->setPriorAccount(acc);
 
501
         AccountListModel::instance()->setPriorAccount(acc);
630
502
   }
631
503
}
632
504
 
633
505
///Update the combobox index
634
506
void SFLPhone::currentPriorAccountChanged(Account* newPrior)
635
507
{
636
 
   if (InstanceInterfaceSingleton::getInstance().connection().isConnected() && newPrior) {
637
 
      m_pAccountStatus->setCurrentIndex(newPrior->getIndex().row());
 
508
   if (DBus::InstanceManager::instance().connection().isConnected() && newPrior) {
 
509
      m_pAccountStatus->setCurrentIndex(newPrior->index().row());
638
510
   }
639
511
   else {
640
512
      kDebug() << "Daemon not responding";
667
539
   }
668
540
} //updateTabIcons
669
541
 
670
 
///Add a new dynamic action (macro)
671
 
void SFLPhone::addMacro(KAction* newAction)
 
542
///Update presence label
 
543
void SFLPhone::updatePresence(const QString& status)
672
544
{
673
 
   actionCollection()->addAction(newAction->objectName() , newAction );
 
545
   m_pPresent->setText(status);
 
546
   m_pPresent->setToolTip(PresenceStatusModel::instance()->currentMessage());
674
547
}
675
548
 
676
 
///Show the toolbar editor
677
 
void SFLPhone::editToolBar()
 
549
///Hide the presence dock when not required
 
550
void SFLPhone::hidePresenceDock()
678
551
{
679
 
   QPointer<KEditToolBar> toolbareditor = new KEditToolBar(guiFactory());
680
 
   toolbareditor->setModal(true);
681
 
   toolbareditor->exec();
682
 
   toolbareditor->setDefaultToolBar("mainToolBar");
683
 
   delete toolbareditor;
 
552
   m_pPresent->setChecked(false);
684
553
}
685
554
 
686
555
#ifdef ENABLE_VIDEO
690
559
   if (!m_pVideoDW) {
691
560
      m_pVideoDW = new VideoDock(this);
692
561
   }
693
 
   m_pVideoDW->setRenderer(r);
 
562
   m_pVideoDW->addRenderer(r);
694
563
   m_pVideoDW->show();
695
564
}
696
565
#endif
698
567
///The daemon is not found
699
568
void SFLPhone::timeout()
700
569
{
701
 
   if (!InstanceInterfaceSingleton::getInstance().connection().isConnected() || !InstanceInterfaceSingleton::getInstance().isValid() || (!model()->isValid())) {
 
570
   if (!DBus::InstanceManager::instance().connection().isConnected() || !DBus::InstanceManager::instance().isValid() || (!CallModel::instance()->isValid())) {
702
571
      KMessageBox::error(this,ErrorMessage::NO_DAEMON_ERROR);
703
572
      exit(1);
704
573
   }
705
574
}
 
575
 
 
576
///Select the call tab
 
577
void SFLPhone::selectCallTab()
 
578
{
 
579
   QList<QTabBar*> tabBars = this->findChildren<QTabBar*>();
 
580
   if(tabBars.count())
 
581
   {
 
582
      foreach(QTabBar* bar, tabBars) {
 
583
         for (int i=0;i<bar->count();i++) {
 
584
            if (bar->tabText(i).replace('&',QString()) == i18n("Call")) {
 
585
               bar->setCurrentIndex(i);
 
586
               break;
 
587
            }
 
588
         }
 
589
      }
 
590
   }
 
591
}