You can now change your name (the one seen by other devices on the network)

This commit is contained in:
Albert Vaca 2015-03-01 21:23:05 -08:00
parent c7c91c1289
commit b0cc45b52a
5 changed files with 123 additions and 4 deletions

View file

@ -162,6 +162,17 @@ void Daemon::onDeviceReachableStatusChanged()
}
}
void Daemon::setAnnouncedName(QString name)
{
KdeConnectConfig::instance()->setName(name);
forceOnNetworkChange();
}
QString Daemon::announcedName()
{
return KdeConnectConfig::instance()->name();
}
Daemon::~Daemon()
{

View file

@ -49,6 +49,9 @@ public Q_SLOTS:
Q_SCRIPTABLE void forceOnNetworkChange();
Q_SCRIPTABLE QString announcedName();
Q_SCRIPTABLE void setAnnouncedName(QString name);
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false) const;

View file

@ -35,7 +35,6 @@
#include <KAboutData>
#include <KLocalizedString>
#include "ui_kcm.h"
#include "interfaces/dbusinterfaces.h"
#include "interfaces/devicesmodel.h"
@ -46,12 +45,13 @@ K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin<KdeConnectKcm>();)
KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
: KCModule(KAboutData::pluginData("kdeconnect-kcm"), parent)
, kcmUi(new Ui::KdeConnectKcmUi())
, daemon(new DaemonDbusInterface(this))
, devicesModel(new DevicesModel(this))
, currentDevice(0)
//, config(KSharedConfig::openConfig("kdeconnectrc"))
{
kcmUi->setupUi(this);
kcmUi->deviceList->setIconSize(QSize(32,32));
sortProxyModel = new DevicesSortProxyModel(devicesModel);
@ -62,6 +62,10 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
kcmUi->progressBar->setVisible(false);
kcmUi->messages->setVisible(false);
kcmUi->rename_label->setText(daemon->announcedName());
kcmUi->rename_edit->setText(daemon->announcedName());
setRenameMode(false);
setButtons(KCModule::NoAdditionalButton);
connect(devicesModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
@ -76,6 +80,38 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList&)
this, SLOT(sendPing()));
connect(kcmUi->refresh_button,SIGNAL(clicked()),
this, SLOT(refresh()));
connect(kcmUi->rename_edit,SIGNAL(returnPressed()),
this, SLOT(renameDone()));
connect(kcmUi->renameDone_button,SIGNAL(clicked()),
this, SLOT(renameDone()));
connect(kcmUi->renameShow_button,SIGNAL(clicked()),
this, SLOT(renameShow()));
}
void KdeConnectKcm::renameShow()
{
setRenameMode(true);
}
void KdeConnectKcm::renameDone()
{
QString newName = kcmUi->rename_edit->text();
if (newName.isEmpty()) {
//Rollback changes
kcmUi->rename_edit->setText(kcmUi->rename_label->text());
} else {
kcmUi->rename_label->setText(newName);
daemon->setAnnouncedName(newName);
}
setRenameMode(false);
}
void KdeConnectKcm::setRenameMode(bool b) {
kcmUi->renameDone_button->setVisible(b);
kcmUi->rename_edit->setVisible(b);
kcmUi->renameShow_button->setVisible(!b);
kcmUi->rename_label->setVisible(!b);
}
KdeConnectKcm::~KdeConnectKcm()
@ -85,8 +121,7 @@ KdeConnectKcm::~KdeConnectKcm()
void KdeConnectKcm::refresh()
{
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "forceOnNetworkChange");
QDBusConnection::sessionBus().call(msg);
daemon->forceOnNetworkChange();
}
void KdeConnectKcm::resetSelection()

View file

@ -26,6 +26,7 @@
class QModelIndex;
class DeviceDbusInterface;
class DaemonDbusInterface;
class DevicesModel;
class DevicesSortProxyModel;
@ -56,9 +57,13 @@ private Q_SLOTS:
void pairingFailed(const QString& error);
void unpaired();
void refresh();
void renameShow();
void renameDone();
void setRenameMode(bool b);
private:
Ui::KdeConnectKcmUi* kcmUi;
DaemonDbusInterface* daemon;
DevicesModel* devicesModel;
DevicesSortProxyModel* sortProxyModel;
DeviceDbusInterface* currentDevice;

View file

@ -32,6 +32,71 @@
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="rename_group_2">
<item>
<widget class="QLabel" name="rename_label">
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>KDE Connect</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="renameShow_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="edit-rename"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="rename_group">
<item>
<widget class="QLineEdit" name="rename_edit">
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="renameDone_button">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="dialog-ok"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListView" name="deviceList"/>
</item>