kdeconnect-kde/kcm/kcm.cpp

105 lines
3.4 KiB
C++
Raw Normal View History

2013-06-19 15:15:25 +01:00
/**
* Copyright 2013 Albert Vaca <albertvaka@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "kcm.h"
#include "ui_kcm.h"
2013-06-25 20:19:17 +01:00
#include "ui_wizard.h"
2013-06-19 15:15:25 +01:00
#include <QtGui/QLabel>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QAction>
#include <QtGui/QStackedLayout>
#include <QtGui/QListView>
2013-06-25 17:08:34 +01:00
#include <QDBusConnection>
#include <QDBusInterface>
2013-06-19 15:15:25 +01:00
#include <KDebug>
#include <kpluginfactory.h>
#include <kstandarddirs.h>
K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin<KdeConnectKcm>();)
K_EXPORT_PLUGIN(KdeConnectKcmFactory("kdeconnect-kcm", "kdeconnect-kcm"))
KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
: KCModule(KdeConnectKcmFactory::componentData(), parent)
2013-06-27 01:13:16 +01:00
, kcmUi(new Ui::KdeConnectKcmUi())
2013-07-02 14:22:05 +01:00
, m_dbusInterface(new DaemonDbusInterface(this))
, pairedDevicesList(new DevicesModel(this))
, addDeviceWizard(new AddDeviceWizard(this))
, config(KSharedConfig::openConfig("kdeconnectrc"))
2013-06-19 15:15:25 +01:00
{
2013-07-02 14:22:05 +01:00
config->group("devices").group("paired").group("123456").writeEntry("name","Ultra-fake device");
config->group("devices").group("paired").group("987654").writeEntry("name","Ultra-fake device");
2013-06-25 17:43:54 +01:00
2013-07-02 14:22:05 +01:00
pairedDevicesList->loadPaired();
2013-06-27 01:13:16 +01:00
kcmUi->setupUi(this);
2013-06-19 15:15:25 +01:00
2013-06-27 01:13:16 +01:00
kcmUi->deviceList->setIconSize(QSize(32,32));
2013-07-02 14:22:05 +01:00
kcmUi->deviceList->setModel(pairedDevicesList);
2013-06-19 15:15:25 +01:00
2013-06-27 01:13:16 +01:00
connect(kcmUi->addButton, SIGNAL(clicked(bool)), this, SLOT(addButtonClicked()));
connect(kcmUi->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked()));
2013-06-25 17:08:34 +01:00
2013-07-02 14:22:05 +01:00
connect(kcmUi->deviceList, SIGNAL(pressed(QModelIndex)), this, SLOT(deviceSelected(QModelIndex)));
connect(addDeviceWizard,SIGNAL(deviceAdded(QString,QString)),this, SLOT(deviceAdded(QString,QString)));
2013-06-19 15:15:25 +01:00
}
KdeConnectKcm::~KdeConnectKcm()
{
}
void KdeConnectKcm::addButtonClicked()
{
2013-07-02 14:22:05 +01:00
addDeviceWizard->show();
2013-06-19 15:15:25 +01:00
}
void KdeConnectKcm::removeButtonClicked()
{
2013-07-02 14:22:05 +01:00
QModelIndex selectedIndex = kcmUi->deviceList->currentIndex();
if (selectedIndex.isValid() && selectedIndex.row() >= 0 && selectedIndex.row() < pairedDevicesList->rowCount()) {
QString id = pairedDevicesList->data(selectedIndex,DevicesModel::IdModelRole).toString();
if (m_dbusInterface->unpairDevice(id)) {;
pairedDevicesList->loadPaired();
}
}
2013-06-19 15:15:25 +01:00
}
void KdeConnectKcm::deviceAdded(QString id,QString name)
{
2013-07-02 14:22:05 +01:00
if (m_dbusInterface->pairDevice(id)) {
qDebug() << "Succesfully paired: " + id;
pairedDevicesList->loadPaired();
}
2013-07-02 01:46:41 +01:00
}
2013-07-02 14:22:05 +01:00
void KdeConnectKcm::deviceSelected(const QModelIndex& current)
2013-06-19 15:15:25 +01:00
{
2013-07-02 14:22:05 +01:00
qDebug() << "PENIS";
kcmUi->removeButton->setEnabled(current.isValid());
2013-06-19 15:15:25 +01:00
}
2013-06-25 17:08:34 +01:00