main-window.cpp 4.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
    Copyright (C) 2011 Collabora Ltd. <info@collabora.com>
      @author George Kiagiadakis <george.kiagiadakis@collabora.com>

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

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

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "main-window.h"
19
#include "debug-message-view.h"
20
#include "telepathy-process.h"
21
22
23
24
25
26
27

#include <TelepathyQt/AccountManager>
#include <TelepathyQt/AccountSet>
#include <TelepathyQt/PendingReady>

#include <QtAlgorithms>

28
29
#include <QAction>
#include <QStatusBar>
30
#include <KToolBar>
31
#include <KLocalizedString>
32

33
34
35
36
37
38
39
MainWindow::MainWindow(QWidget *parent)
    : KXmlGuiWindow(parent)
{
    setCentralWidget(new QWidget(this));
    m_ui.setupUi(centralWidget());
    setupGUI();

40
41
42
    TelepathyProcess *process = new TelepathyProcess(this);
    process->setOwnerId(QStringLiteral("org.freedesktop.Telepathy.MissionControl5"));
    m_ui.mcLogsView->setTelepathyProcess(process);
43

44
45
46
    m_AccountManager = Tp::AccountManager::create();
    Tp::PendingReady *pendingReady = m_AccountManager->becomeReady();
    connect(pendingReady, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onAccountManagerBecameReady(Tp::PendingOperation*)));
47

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
48
    QAction *saveLogAction = new QAction(QIcon::fromTheme(QLatin1String("document-save-as")), i18n("Save Log"), this);
49
50
51
    saveLogAction->setToolTip(i18nc("Toolbar icon tooltip", "Save log of the current tab"));
    toolBar()->addAction(saveLogAction);

52
    connect(m_ui.mcLogsView, SIGNAL(statusMessage(QString)), statusBar(), SLOT(showMessage(QString)));
53
    connect(saveLogAction, SIGNAL(triggered(bool)), this, SLOT(saveLogFile()));
54
55
56
57
58
59
60
}

MainWindow::~MainWindow()
{

}

61
62
63
void MainWindow::saveLogFile()
{
    m_ui.tabWidget->currentWidget()->findChild<DebugMessageView *>()->saveLogFile();
64
}
65
66
67
68

void MainWindow::onAccountManagerBecameReady(Tp::PendingOperation* op)
{
    if (op->isError()) {
69
        qCritical() << "Failed to initialize Tp::AccountManager"
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
                 << "Error was:" << op->errorName() << "-" << op->errorMessage();
    } else {
        QSet<QString> connectionManagers;

        Tp::AccountSetPtr accountSetPtr = m_AccountManager->onlineAccounts();
        QList<Tp::AccountPtr> accountList = accountSetPtr->accounts();

        Q_FOREACH(Tp::AccountPtr account, accountList) {
            connectionManagers.insert(account->cmName());
        }

        initConnectionManagerTabs(connectionManagers);
    }
}

void MainWindow::initConnectionManagerTabs(const QSet<QString>& connectionManagerSet)
{
    QStringList connectionManagerStringList = connectionManagerSet.toList();
Jonah Brüchert's avatar
Jonah Brüchert committed
88
    std::sort(connectionManagerStringList.begin(), connectionManagerStringList.end());
89
90
91
92
93

    Q_FOREACH(QString connectionManager, connectionManagerStringList) {
        QWidget *cmTab = new QWidget();
        QHBoxLayout *horizontalLayout = new QHBoxLayout(cmTab);
        DebugMessageView *cmDebugMessageView = new DebugMessageView(cmTab);
94
95
96
97

        TelepathyProcess *process = new TelepathyProcess(cmDebugMessageView);
        process->setOwnerId(QString(QStringLiteral("org.freedesktop.Telepathy.ConnectionManager.%1")).arg(connectionManager));
        cmDebugMessageView->setTelepathyProcess(process);
98
99
100
101
102
103
104
105
106
107
108

        horizontalLayout->addWidget(cmDebugMessageView);

        // Convert the connectionManager to title case. eg. haze to Haze
        QString tabText = connectionManager;
        tabText[0] = tabText[0].toTitleCase();
        m_ui.tabWidget->addTab(cmTab, tabText);

        connect(cmDebugMessageView, SIGNAL(statusMessage(QString)), statusBar(), SLOT(showMessage(QString)));
    }
}