source: qutecom-2.2/qutecom/src/presentation/qt/QtToolBar.cpp @ 666:2852829a2283

Last change on this file since 666:2852829a2283 was 666:2852829a2283, checked in by laurent, Dmitriy.Trt, 3 years ago

utf8 support

File size: 21.2 KB
Line 
1/*
2 * QuteCom, a voice over Internet phone
3 * Copyright (C) 2010 Mbdsys
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#include "QtToolBar.h"
21
22#include "ui_QuteComWindow.h"
23
24#include <cutil/global.h>
25
26#include "QtQuteCom.h"
27#include "QtAbout.h"
28#include "QtNoQuteComAlert.h"
29#include "profile/QtProfileDetails.h"
30#include "profile/QtUserProfileHandler.h"
31#include "config/QtQuteComConfigDialog.h"
32#include "webservices/sms/QtSms.h"
33#include "phonecall/QtContactCallListWidget.h"
34#include "phonecall/QtPhoneCall.h"
35#include "contactlist/QtContactList.h"
36#include "filetransfer/QtFileTransfer.h"
37#include "filetransfer/QtFileTransferWidget.h"
38#include "conference/QtConferenceCallWidget.h"
39
40#include "webdirectory/QtWebDirectory.h"
41
42#include <control/CQuteCom.h>
43#include <control/history/CHistory.h>
44#include <control/phonecall/CPhoneCall.h>
45#include <control/phoneline/CPhoneLine.h>
46#include <control/profile/CUserProfile.h>
47#include <control/profile/CUserProfileHandler.h>
48
49#include <model/contactlist/ContactProfile.h>
50#include <model/phonecall/ConferenceCall.h>
51#include <model/account/qutecom/QuteComAccount.h>
52#include <model/profile/UserProfile.h>
53#include <model/history/History.h>
54#include <model/config/ConfigManager.h>
55#include <model/config/Config.h>
56#include <model/config/EnumToolBarMode.h>
57
58#include <util/Logger.h>
59
60#include <qtutil/WidgetBackgroundImage.h>
61#include <qtutil/SafeConnect.h>
62#include <qtutil/Object.h>
63#include <qtutil/WidgetFactory.h>
64
65#include <QtGui/QMessageBox>
66//#include <QtGui/QToolButton>
67
68static const int TOOLBAR_BUTTON_MINIMUM_WIDTH = 60;
69
70void QtToolBar::connectOrHide(bool condition, QAction* action, QObject* receiver, const char* slot) {
71        if (condition) {
72                SAFE_CONNECT_RECEIVER(action, SIGNAL(triggered()), receiver, slot);
73        } else {
74#if QT_VERSION >= 0x040200
75                Q_FOREACH(QWidget* widget, action->associatedWidgets()) {
76                        widget->removeAction(action);
77                }
78#else
79                Q_FOREACH(QMenu* menu, _ui->menuBar->findChildren<QMenu*>()) {
80                        menu->removeAction(action);
81                }
82                _ui->toolBar->removeAction(action);
83#endif
84        }
85}
86
87
88void QtToolBar::connectOrHide(WsUrl::Page page, QAction* action, QObject* receiver, const char* slot) {
89        connectOrHide(WsUrl::hasPage(page), action, receiver, slot);
90}
91
92
93QtToolBar::QtToolBar(QtQuteCom & qtQuteCom, Ui::QuteComWindow * qtQuteComUi, QWidget * parent)
94        : QObject(parent),
95        _qtQuteCom(qtQuteCom),
96        _cQuteCom(_qtQuteCom.getCQuteCom()) {
97
98        _ui = qtQuteComUi;
99
100        Config & config = ConfigManager::getInstance().getCurrentConfig();
101        bool canSendSms = config.getSmsFeatureEnabled();
102        bool canDoConference = config.getAudioConferenceFeatureEnabled();
103
104        SAFE_CONNECT(&_qtQuteCom, SIGNAL(userProfileDeleted()), SLOT(userProfileDeleted()));
105
106        // actions initialization
107        _userIsLogged = false;
108        updateActionsAccordingToUserStatus();
109        ////
110
111        //menuQuteCom
112        connectOrHide(WsUrl::Account, _ui->actionShowQuteComAccount, this, SLOT(showQuteComAccount()) );
113        SAFE_CONNECT(_ui->actionEditMyProfile, SIGNAL(triggered()), SLOT(editMyProfile()));
114        SAFE_CONNECT(_ui->actionLogOff, SIGNAL(triggered()), SLOT(logOff()));
115        connectOrHide(WsUrl::CallOut, _ui->actionQuteComServices, this, SLOT(showQuteComServices()) );
116        SAFE_CONNECT_RECEIVER(_ui->actionClose, SIGNAL(triggered()), &_qtQuteCom, SLOT(closeWindow()));
117        SAFE_CONNECT_RECEIVER(_ui->actionQuit, SIGNAL(triggered()), &_qtQuteCom, SLOT(prepareToExitApplication()));
118
119        //menuContacts
120        SAFE_CONNECT(_ui->actionAddContact, SIGNAL(triggered()), SLOT(addContact()));
121        connectOrHide(WsUrl::Directory, _ui->actionSearchQuteComContact, this, SLOT(searchQuteComContact()) );
122        SAFE_CONNECT(_ui->actionShowHideOfflineContacts, SIGNAL(triggered()), SLOT(showHideOfflineContacts()));
123        SAFE_CONNECT(_ui->actionShowHideContactGroups, SIGNAL(triggered()), SLOT(showHideContactGroups()));
124
125        //menuActions
126        connectOrHide(canDoConference, _ui->actionCreateConferenceCall, this, SLOT(createConferenceCall()));
127        connectOrHide(canSendSms, _ui->actionSendSms, this, SLOT(sendSms()));
128        SAFE_CONNECT(_ui->actionAcceptCall, SIGNAL(triggered()), SLOT(acceptCall()));
129        SAFE_CONNECT(_ui->actionHangUpCall, SIGNAL(triggered()), SLOT(hangUpCall()));
130        SAFE_CONNECT(_ui->actionHoldResumeCall, SIGNAL(triggered()), SLOT(holdResumeCall()));
131
132        //menuHelp
133        connectOrHide(WsUrl::Forum, _ui->actionShowQuteComForum, this, SLOT(showQuteComForum()));
134        connectOrHide(WsUrl::FAQ, _ui->actionQuteComFAQ, this, SLOT(showQuteComFAQ()));
135        SAFE_CONNECT(_ui->actionShowAbout, SIGNAL(triggered()), SLOT(showAbout()));
136
137        //menuTools
138        SAFE_CONNECT(_ui->actionShowConfig, SIGNAL(triggered()), SLOT(showConfig()));
139        SAFE_CONNECT(_ui->actionShowFileTransfer, SIGNAL(triggered()), SLOT(showFileTransferWindow()));
140        SAFE_CONNECT(_ui->actionToggleVideo, SIGNAL(triggered()), SLOT(toggleVideo()));
141
142        //menuClearHistory
143        SAFE_CONNECT(_ui->actionClearOutgoingCalls, SIGNAL(triggered()), SLOT(clearHistoryOutgoingCalls()));
144        SAFE_CONNECT(_ui->actionClearIncomingCalls, SIGNAL(triggered()), SLOT(clearHistoryIncomingCalls()));
145        SAFE_CONNECT(_ui->actionClearMissedCalls, SIGNAL(triggered()), SLOT(clearHistoryMissedCalls()));
146        SAFE_CONNECT(_ui->actionClearRejectedCalls, SIGNAL(triggered()), SLOT(clearHistoryRejectedCalls()));
147        SAFE_CONNECT(_ui->actionClearChatSessions, SIGNAL(triggered()), SLOT(clearHistoryChatSessions()));
148        connectOrHide(canSendSms, _ui->actionClearSms, this, SLOT(clearHistorySms()));
149        SAFE_CONNECT(_ui->actionClearAll, SIGNAL(triggered()), SLOT(clearHistoryAll()));
150
151        //Open chat window button
152        _ui->actionOpenChatWindow->setEnabled(false);
153        SAFE_CONNECT(_ui->actionOpenChatWindow, SIGNAL(triggered()), SLOT(showChatWindow()));
154
155        //Get notified of config changes
156        config.valueChangedEvent += boost::bind(&QtToolBar::configChangedEventHandler, this, _1);
157        SAFE_CONNECT(this, SIGNAL(configChanged(QString)), SLOT(slotConfigChanged(QString)) );
158
159        // Update toolbar mode
160        updateToolBar();
161       
162        //a menu is about to be displayed
163        SAFE_CONNECT(_ui->menuActions, SIGNAL(aboutToShow()), SLOT(updateMenuActions()));
164
165#ifndef CUSTOM_ACCOUNT
166        _ui->actionSearchQuteComContact->setVisible(false);
167#endif
168
169#ifdef DISABLE_SMS
170        _ui->actionClearSms->setVisible(false);
171        _ui->actionSendSms->setVisible(false);
172#endif
173
174#ifdef DISABLE_FILETRANSFER
175        _ui->actionShowFileTransfer->setVisible(false);
176#endif
177
178}
179
180QtToolBar::~QtToolBar() {
181}
182
183QWidget * QtToolBar::getWidget() const {
184        return _qtQuteCom.getWidget();
185}
186
187void QtToolBar::showQuteComAccount() {
188        if (_cQuteCom.getCUserProfileHandler().getCUserProfile()) {
189                //WARNING should not be called when no UserProfile set
190                WsUrl::showQuteComAccount();
191        }
192}
193
194void QtToolBar::editMyProfile() {
195        if (_cQuteCom.getCUserProfileHandler().getCUserProfile()) {
196                QWidget * parent = qobject_cast<QWidget *>(sender()->parent());
197
198                //FIXME this method should not be called if no UserProfile has been set
199                QtProfileDetails qtProfileDetails(*_cQuteCom.getCUserProfileHandler().getCUserProfile(),
200                        _cQuteCom.getCUserProfileHandler().getCUserProfile()->getUserProfile(),
201                        parent, tr("Edit My Profile"));
202
203                //TODO UserProfile must be updated if QtProfileDetails was accepted
204                qtProfileDetails.show();
205        }
206}
207
208void QtToolBar::addContact() {
209        if (_cQuteCom.getCUserProfileHandler().getCUserProfile()) {
210                QWidget * parent = qobject_cast<QWidget *>(sender()->parent());
211
212                //FIXME this method should not be called if no UserProfile has been set
213                ContactProfile contactProfile;
214                QtProfileDetails qtProfileDetails(*_cQuteCom.getCUserProfileHandler().getCUserProfile(),
215                        contactProfile, parent, tr("Add a Contact"));
216                if (qtProfileDetails.show()) {
217                        _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCContactList().addContact(contactProfile);
218                }
219        }
220}
221
222void QtToolBar::showConfig() {
223        QtQuteComConfigDialog::showInstance(_cQuteCom);
224}
225
226void QtToolBar::updateShowHideOfflineContactsAction() {
227        Config & config = ConfigManager::getInstance().getCurrentConfig();
228        QString text;
229        if (config.getShowOfflineContacts()) {
230                text = tr("Hide Unavailable Contacts");
231        } else {
232                text = tr("Show Unavailable Contacts");
233        }
234
235        _ui->actionShowHideOfflineContacts->setText(text);
236}
237
238void QtToolBar::updateShowHideContactGroupsAction() {
239        Config & config = ConfigManager::getInstance().getCurrentConfig();
240        QString text;
241        if (config.getShowGroups()) {
242                text = tr("Hide Groups");
243        } else {
244                text = tr("Show Groups");
245        }
246
247        _ui->actionShowHideContactGroups->setText(text);
248}
249
250void QtToolBar::updateToggleVideoAction() {
251        Config & config = ConfigManager::getInstance().getCurrentConfig();
252
253        bool videoEnabled = config.getVideoEnable();
254        QString text;
255        if (videoEnabled) {
256                text = tr("Disable &Video Calls");
257        } else {
258                text = tr("Enable &Video Calls");
259        }
260
261        _ui->actionToggleVideo->setText(text);
262        _ui->actionToggleVideo->setEnabled(!config.getVideoWebcamDevice().empty());
263}
264
265void QtToolBar::showQuteComForum() {
266        WsUrl::showQuteComForum();
267}
268
269void QtToolBar::showQuteComServices() {
270        WsUrl::showQuteComCallOut();
271}
272
273void QtToolBar::searchQuteComContact() {
274
275        QtWebDirectory * qtWebDirectory = _qtQuteCom.getQtWebDirectory();
276        if (qtWebDirectory) {
277                qtWebDirectory->raise();
278        }
279}
280
281void QtToolBar::showAbout() {
282        QWidget * parent = qobject_cast<QWidget *>(sender()->parent());
283        static QtAbout * qtAbout = new QtAbout(parent);
284        qtAbout->getWidget()->show();
285}
286
287void QtToolBar::sendSms() {
288
289        CUserProfile * cuserprofile = _cQuteCom.getCUserProfileHandler().getCUserProfile();
290        if (cuserprofile) {
291                if (cuserprofile->getUserProfile().hasQuteComAccount()) {
292                        QtSms * qtSms = _qtQuteCom.getQtSms();
293                        if (qtSms) {
294                                QWidget * parent = qobject_cast<QWidget *>(sender()->parent());
295                                qtSms->getWidget()->setParent(parent, Qt::Dialog);
296                                qtSms->getWidget()->show();
297                        }
298                        return;
299                } else {
300                        QtNoQuteComAlert noQuteComAlert(NULL, _qtQuteCom);
301                        noQuteComAlert.getQDialog()->exec();
302                }
303        }
304}
305
306void QtToolBar::createConferenceCall() {
307
308        CUserProfile * cUserProfile = _cQuteCom.getCUserProfileHandler().getCUserProfile();
309        if (cUserProfile) {
310
311                IPhoneLine * phoneLine = cUserProfile->getUserProfile().getActivePhoneLine();
312                if (phoneLine) {
313                        if (phoneLine->getActivePhoneCall()) {
314                                QMessageBox::information(
315                                        _qtQuteCom.getWidget(),
316                                        tr("@product@ - Proceed Conference"), 
317                                        tr("<b>Conference can't be started while there are active phone calls.</b><br><br>"
318                                        "Finish all phone calls and try again.")
319                                        );
320                        } else {
321                                QtConferenceCallWidget conferenceDialog(_qtQuteCom.getWidget(), _cQuteCom, phoneLine);
322                                conferenceDialog.exec();
323                        }
324                }
325        }
326}
327
328void QtToolBar::showQuteComFAQ() {
329        WsUrl::showQuteComFAQ();
330}
331
332void QtToolBar::showHideOfflineContacts() {
333        QtContactList * qtContactList = _qtQuteCom.getQtContactList();
334        if (qtContactList) {
335                Config & config = ConfigManager::getInstance().getCurrentConfig();
336                config.set(Config::GENERAL_SHOW_OFFLINE_CONTACTS_KEY, !config.getShowOfflineContacts());
337                qtContactList->updatePresentation();
338
339                updateShowHideOfflineContactsAction();
340        }
341}
342
343void QtToolBar::showHideContactGroups() {
344        QtContactList * qtContactList = _qtQuteCom.getQtContactList();
345        if (qtContactList) {
346                Config & config = ConfigManager::getInstance().getCurrentConfig();
347                config.set(Config::GENERAL_SHOW_GROUPS_KEY, !config.getShowGroups());
348                qtContactList->updatePresentation();
349
350                updateShowHideContactGroupsAction();
351        }
352}
353
354void QtToolBar::toggleVideo() {
355        Config & config = ConfigManager::getInstance().getCurrentConfig();
356        config.set(Config::VIDEO_ENABLE_KEY, !config.getVideoEnable());
357}
358
359void QtToolBar::clearHistoryOutgoingCalls() {
360        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
361                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
362                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::OutgoingCall);
363        }
364}
365
366void QtToolBar::clearHistoryIncomingCalls() {
367        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
368                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
369                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::IncomingCall);
370        }
371}
372
373void QtToolBar::clearHistoryMissedCalls() {
374        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
375                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
376                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::MissedCall);
377        }
378}
379
380void QtToolBar::clearHistoryRejectedCalls() {
381        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
382                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
383                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::RejectedCall);
384        }
385}
386
387void QtToolBar::clearHistoryChatSessions() {
388        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
389                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
390                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::ChatSession);
391        }
392}
393
394void QtToolBar::clearHistorySms() {
395        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
396                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
397                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::OutgoingSmsOk);
398        }
399}
400
401void QtToolBar::clearHistoryAll() {
402        if (_cQuteCom.getCUserProfileHandler().getCUserProfile() &&
403                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()) {
404                _cQuteCom.getCUserProfileHandler().getCUserProfile()->getCHistory()->clear(HistoryMemento::Any);
405        }
406}
407
408void QtToolBar::logOff() {
409        if (_userIsLogged) {
410                // check for pending calls
411                CUserProfile *cUserProfile = _cQuteCom.getCUserProfileHandler().getCUserProfile();
412                if (cUserProfile) {
413                        CPhoneLine *cPhoneLine = cUserProfile->getCPhoneLine();
414                        if (cPhoneLine) {
415                                if (cPhoneLine->hasPendingCalls()) {
416                                       
417                                        if (QMessageBox::question(
418                                                _qtQuteCom.getWidget(),
419                                                tr("@product@ - Warning"),
420                                                tr("You have unfinished call(s).") + "\n" +
421                                                        tr("Are you sure you want to log off?"),
422                                                tr("&Log Off"),
423                                                tr("&Cancel")
424                                        ) == 1)  {
425                                                return;
426                                        }
427                                }
428                        }
429                }
430                ////
431                // Close Chat
432                _qtQuteCom.closeChatWindow ();
433               
434                // disable menubar and toolbar to avoid crashes
435                //_ui->menuBar->setEnabled(false);
436                _ui->actionLogOff->setEnabled(false);
437                _ui->toolBar->setEnabled(false);
438                ////
439        }
440
441        // Calling this when the user has already been logged off is harmless and
442        // will bring the login dialog.
443        _cQuteCom.getCUserProfileHandler().logOff();
444}
445
446int QtToolBar::findFirstCallTab() {
447        QtContactCallListWidget * widget;
448        for (int i = 0; i < _ui->tabWidget->count(); i++) {
449                widget = dynamic_cast<QtContactCallListWidget *>(_ui->tabWidget->widget(i));
450                if (widget) {
451                        return i;
452                }
453        }
454        return -1;
455}
456
457void QtToolBar::acceptCall() {
458        int callIndex = findFirstCallTab();
459        if (callIndex == -1) {
460                return;
461        }
462        QtContactCallListWidget * widget = (QtContactCallListWidget *) _ui->tabWidget->widget(callIndex);
463        if (!widget) {
464                return;
465        }
466
467        QtPhoneCall * qtPhoneCall = widget->getFirstQtPhoneCall();
468        if (qtPhoneCall) {
469                qtPhoneCall->acceptCall();
470        }
471}
472
473void QtToolBar::holdResumeCall() {
474        int callIndex = findFirstCallTab();
475        if (callIndex == -1) {
476                return;
477        }
478        QtContactCallListWidget * widget = (QtContactCallListWidget *) _ui->tabWidget->widget(callIndex);
479        if (!widget) {
480                return;
481        }
482
483        QtPhoneCall * qtPhoneCall = widget->getFirstQtPhoneCall();
484        if (qtPhoneCall) {
485                qtPhoneCall->holdOrResume();
486        }
487}
488
489void QtToolBar::hangUpCall() {
490        int callIndex = findFirstCallTab();
491        if (callIndex == -1) {
492                return;
493        }
494        QtContactCallListWidget * widget;
495
496        widget = (QtContactCallListWidget *) _ui->tabWidget->widget(callIndex);
497        if (!widget) {
498                return;
499        }
500        widget->hangup();
501}
502
503void QtToolBar::updateMenuActions() {
504
505        bool accept = false, holdResume = false, hangUp = false;
506       
507        int callIndex = findFirstCallTab();
508        if (callIndex > 0) {
509
510                QtContactCallListWidget * widget = (QtContactCallListWidget *) _ui->tabWidget->widget(callIndex);
511                if (widget) {
512
513                        QtPhoneCall * qtPhoneCall = widget->getFirstQtPhoneCall();
514
515                        if (qtPhoneCall) {
516
517                                switch (qtPhoneCall->getCPhoneCall().getState()) {
518                                       
519                                        case EnumPhoneCallState::PhoneCallStateResumed:
520                                        case EnumPhoneCallState::PhoneCallStateTalking: {
521                                                holdResume = true;
522                                                hangUp = true;
523                                                break;
524                                        }
525                                       
526                                        case EnumPhoneCallState::PhoneCallStateDialing:
527                                        case EnumPhoneCallState::PhoneCallStateRinging: {
528                                                hangUp = true;
529                                                break;
530                                        }
531                                       
532                                        case EnumPhoneCallState::PhoneCallStateIncoming: {
533                                                accept = true;
534                                                hangUp = true;
535                                                break;
536                                        }
537                                       
538                                        case EnumPhoneCallState::PhoneCallStateHold: {
539                                                holdResume= true;
540                                                hangUp = true;
541                                                break;
542                                        }
543                                       
544                                        case EnumPhoneCallState::PhoneCallStateError: {
545                                                hangUp = true;
546                                                break;
547                                        }
548                                       
549                                        // other cases -> set all to false
550                                        case EnumPhoneCallState::PhoneCallStateMissed :
551                                        case EnumPhoneCallState::PhoneCallStateRedirected:
552                                        case EnumPhoneCallState::PhoneCallStateClosed:
553                                        case EnumPhoneCallState::PhoneCallStateUnknown:
554                                        default: {
555                                                //accept = holdResume = hangUp = false;
556                                        }
557                                }
558                        }
559                }
560        }
561
562        _ui->actionAcceptCall->setEnabled(accept);
563        _ui->actionHangUpCall->setEnabled(hangUp);
564        _ui->actionHoldResumeCall->setEnabled(holdResume);
565}
566
567void QtToolBar::showChatWindow() {
568        QWidget * chatWindow = _qtQuteCom.getChatWindow();
569        if (chatWindow) {
570                chatWindow->showNormal();
571                chatWindow->activateWindow();
572        }
573}
574
575void QtToolBar::showFileTransferWindow() {
576
577        QtFileTransfer * fileTransfer = _qtQuteCom.getFileTransfer();
578        if (fileTransfer) {
579                        fileTransfer->getFileTransferWidget()->show();
580        }
581}
582
583void QtToolBar::retranslateUi() {
584        updateShowHideContactGroupsAction();
585        updateShowHideOfflineContactsAction();
586        updateToggleVideoAction();
587        updateActionsAccordingToUserStatus();
588}
589
590void QtToolBar::configChangedEventHandler(const std::string & key) {
591        configChanged(QString::fromUtf8(key.c_str()));
592}
593
594void QtToolBar::slotConfigChanged(QString qkey) {
595        std::string key(qkey.toUtf8());
596        if (key == Config::VIDEO_ENABLE_KEY || key == Config::VIDEO_WEBCAM_DEVICE_KEY) {
597                updateToggleVideoAction();
598        }
599
600        if (key == Config::GENERAL_TOOLBARMODE_KEY) {
601                updateToolBar();
602        }
603}
604
605void QtToolBar::updateToolBar() {
606       
607#if defined(OS_MACOSX)
608        EnumToolBarMode::ToolBarMode toolBarMode = EnumToolBarMode::ToolBarModeIconsOnly;
609#else   
610        Config & config = ConfigManager::getInstance().getCurrentConfig();
611        std::string text = config.getToolBarMode();
612        EnumToolBarMode::ToolBarMode toolBarMode = EnumToolBarMode::toToolBarMode(text);       
613#endif
614       
615        if (toolBarMode == EnumToolBarMode::ToolBarModeHidden) {
616                _ui->toolBar->hide();
617
618        } else if (toolBarMode == EnumToolBarMode::ToolBarModeIconsOnly) {
619                _ui->toolBar->show();
620                _ui->toolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
621
622                // Restore icon width in case it was set by TextUnderIcon mode
623                QSize size = _ui->toolBar->iconSize();
624                size.setWidth(size.height());
625                _ui->toolBar->setIconSize(size);
626
627        } else if (toolBarMode == EnumToolBarMode::ToolBarModeTextUnderIcons) {
628                _ui->toolBar->show();
629                _ui->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
630                QSize size = _ui->toolBar->iconSize();
631                size.setWidth(TOOLBAR_BUTTON_MINIMUM_WIDTH);
632                _ui->toolBar->setIconSize(size);
633
634        } else {
635                LOG_WARN("Unknown toolbar mode: " + toolBarMode);
636        }
637}
638
639void QtToolBar::userProfileDeleted() {
640        _userIsLogged = false;
641        updateActionsAccordingToUserStatus();
642}
643
644void QtToolBar::userProfileIsInitialized() {
645        _userIsLogged = true;
646        updateActionsAccordingToUserStatus();
647}
648
649void QtToolBar::enableMenuBar() {
650        _ui->menuBar->setEnabled(true);
651}
652
653void QtToolBar::updateActionsAccordingToUserStatus() {
654        // We need to use a boolean to keep trace of the user status because when
655        // userProfileDeleted is called, the user profile is still alive, even if
656        // it's not for a long time.
657        if (_userIsLogged) {
658                _ui->actionLogOff->setText(tr("Log &Off..."));
659        } else {
660                _ui->actionLogOff->setText(tr("Log &On..."));
661        }
662        //_ui->menuBar->setEnabled(_userIsLogged);
663        _ui->toolBar->setEnabled(_userIsLogged);
664
665        // This list contains all actions which needs a logged user to work
666        QList<QAction*> loggedInActions;
667        loggedInActions
668        << _ui->actionShowQuteComAccount
669        << _ui->actionAddContact
670        << _ui->actionSendSms
671        << _ui->actionEditMyProfile
672        << _ui->actionCreateConferenceCall
673        << _ui->actionShowHideOfflineContacts
674        << _ui->actionClearChatSessions
675        << _ui->actionClearAll
676        << _ui->actionSearchQuteComContact
677        << _ui->actionAcceptCall
678        << _ui->actionHangUpCall
679        << _ui->actionHoldResumeCall
680        << _ui->actionShowHideContactGroups
681        << _ui->actionOpenChatWindow
682        << _ui->actionClearOutgoingCalls
683        << _ui->actionClearIncomingCalls
684        << _ui->actionClearMissedCalls
685        << _ui->actionToggleVideo
686        << _ui->actionClearSms
687        << _ui->actionShowFileTransfer
688        << _ui->actionClearRejectedCalls
689        ;
690        Q_FOREACH(QAction* action, loggedInActions) {
691                action->setEnabled(_userIsLogged);
692        }
693
694}
695
696void QtToolBar::tryingToConnect()
697{
698        _ui->actionLogOff->setText(tr("Log &Off..."));
699        _ui->actionLogOff->setEnabled(true);
700}
701
Note: See TracBrowser for help on using the repository browser.