Merge branch 'master' into frameworks
Conflicts: cli/kdeconnect-cli.cpp core/filetransferjob.cpp core/filetransferjob.h interfaces/notificationsmodel.cpp plasmoid/declarativeplugin/kdeconnectdeclarativeplugin.h plugins/sftp/sftpplugin.cpp
This commit is contained in:
commit
6cc6d287fc
10 changed files with 47 additions and 42 deletions
|
@ -28,18 +28,17 @@
|
||||||
#include <KIO/RenameDialog>
|
#include <KIO/RenameDialog>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
|
||||||
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl &destination): KJob()
|
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl& destination)
|
||||||
|
: KJob()
|
||||||
|
, mOrigin(origin)
|
||||||
|
, mDestinationJob(0)
|
||||||
|
, mDeviceName("KDE Connect")
|
||||||
|
, mDestination(destination)
|
||||||
|
, mSpeedBytes(0)
|
||||||
|
, mSize(size)
|
||||||
|
, mWritten(0)
|
||||||
{
|
{
|
||||||
Q_ASSERT(destination.isLocalFile());
|
Q_ASSERT(destination.isLocalFile());
|
||||||
//TODO: Make a precondition before calling this function that destination file exists
|
|
||||||
mOrigin = origin;
|
|
||||||
mSize = size;
|
|
||||||
mWritten = 0;
|
|
||||||
m_speedBytes = 0;
|
|
||||||
mDestination = destination;
|
|
||||||
mDestinationJob = 0;
|
|
||||||
mDeviceName = i18nc("Device name that will appear on the jobs", "KDE-Connect");
|
|
||||||
|
|
||||||
setCapabilities(Killable);
|
setCapabilities(Killable);
|
||||||
qCDebug(KDECONNECT_CORE) << "FileTransferJob Downloading payload to" << destination;
|
qCDebug(KDECONNECT_CORE) << "FileTransferJob Downloading payload to" << destination;
|
||||||
}
|
}
|
||||||
|
@ -117,14 +116,14 @@ void FileTransferJob::startTransfer()
|
||||||
{
|
{
|
||||||
setTotalAmount(Bytes, mSize);
|
setTotalAmount(Bytes, mSize);
|
||||||
setProcessedAmount(Bytes, 0);
|
setProcessedAmount(Bytes, 0);
|
||||||
m_time = QTime::currentTime();
|
mTime = QTime::currentTime();
|
||||||
description(this, i18n("Receiving file over KDE-Connect"),
|
description(this, i18n("Receiving file over KDE-Connect"),
|
||||||
QPair<QString, QString>(i18nc("File transfer origin", "From"),
|
QPair<QString, QString>(i18nc("File transfer origin", "From"),
|
||||||
QString(mDeviceName)),
|
QString(mDeviceName)),
|
||||||
QPair<QString, QString>(i18nc("File transfer destination", "To"), mDestination.path()));
|
QPair<QString, QString>(i18nc("File transfer destination", "To"), mDestination.path()));
|
||||||
|
|
||||||
QFile(mDestination.path()).open(QIODevice::WriteOnly | QIODevice::Truncate); //HACK: KIO is so dumb it can't create the file if it doesn't exist
|
|
||||||
mDestinationJob = KIO::open(mDestination, QIODevice::WriteOnly);
|
mDestinationJob = KIO::open(mDestination, QIODevice::WriteOnly);
|
||||||
|
QFile(mDestination.path()).open(QIODevice::WriteOnly | QIODevice::Truncate); //KIO won't create the file if it doesn't exist
|
||||||
connect(mDestinationJob, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*)));
|
connect(mDestinationJob, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*)));
|
||||||
connect(mDestinationJob, SIGNAL(result(KJob*)), this, SLOT(openFinished(KJob*)));
|
connect(mDestinationJob, SIGNAL(result(KJob*)), this, SLOT(openFinished(KJob*)));
|
||||||
|
|
||||||
|
@ -165,15 +164,15 @@ void FileTransferJob::readyRead()
|
||||||
|
|
||||||
if (mSize > -1) {
|
if (mSize > -1) {
|
||||||
//If a least 1 second has passed since last update
|
//If a least 1 second has passed since last update
|
||||||
int secondsSinceLastTime = m_time.secsTo(QTime::currentTime());
|
int secondsSinceLastTime = mTime.secsTo(QTime::currentTime());
|
||||||
if (secondsSinceLastTime > 0 && m_speedBytes > 0) {
|
if (secondsSinceLastTime > 0 && mSpeedBytes > 0) {
|
||||||
float speed = (mWritten - m_speedBytes) / secondsSinceLastTime;
|
float speed = (mWritten - mSpeedBytes) / secondsSinceLastTime;
|
||||||
emitSpeed(speed);
|
emitSpeed(speed);
|
||||||
|
|
||||||
m_time = QTime::currentTime();
|
mTime = QTime::currentTime();
|
||||||
m_speedBytes = mWritten;
|
mSpeedBytes = mWritten;
|
||||||
} else if(m_speedBytes == 0) {
|
} else if(mSpeedBytes == 0) {
|
||||||
m_speedBytes = mWritten;
|
mSpeedBytes = mWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl &destination);
|
FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl &destination);
|
||||||
virtual void start();
|
virtual void start();
|
||||||
QUrl destination() const { return mDestination; }
|
QUrl destination() const { return mDestination; }
|
||||||
void setDeviceName(const QString &deviceName) {mDeviceName = deviceName;};
|
void setDeviceName(const QString &deviceName) { mDeviceName = deviceName; }
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void doStart();
|
void doStart();
|
||||||
|
@ -59,11 +59,10 @@ private:
|
||||||
KIO::FileJob* mDestinationJob;
|
KIO::FileJob* mDestinationJob;
|
||||||
QString mDeviceName;
|
QString mDeviceName;
|
||||||
QUrl mDestination;
|
QUrl mDestination;
|
||||||
QTime m_time;
|
QTime mTime;
|
||||||
qulonglong m_speedBytes;
|
qulonglong mSpeedBytes;
|
||||||
qint64 mSize;
|
qint64 mSize;
|
||||||
qint64 mWritten;
|
qint64 mWritten;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,10 +40,10 @@ class KDECONNECTINTERFACES_EXPORT DevicesModel
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ModelRoles {
|
enum ModelRoles {
|
||||||
NameModelRole = Qt::DisplayRole,
|
NameModelRole = Qt::DisplayRole,
|
||||||
IconModelRole = Qt::DecorationRole,
|
IconModelRole = Qt::DecorationRole,
|
||||||
StatusModelRole = Qt::InitialSortOrderRole,
|
StatusModelRole = Qt::InitialSortOrderRole,
|
||||||
IdModelRole = Qt::UserRole,
|
IdModelRole = Qt::UserRole,
|
||||||
IconNameRole
|
IconNameRole
|
||||||
};
|
};
|
||||||
enum StatusFlag {
|
enum StatusFlag {
|
||||||
|
|
|
@ -48,9 +48,11 @@ NotificationsModel::NotificationsModel(QObject* parent)
|
||||||
|
|
||||||
QHash<int, QByteArray> NotificationsModel::roleNames() const
|
QHash<int, QByteArray> NotificationsModel::roleNames() const
|
||||||
{
|
{
|
||||||
|
//Role names for QML
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(DbusInterfaceRole, "dbusInterface");
|
names.insert(DbusInterfaceRole, "dbusInterface");
|
||||||
names.insert(AppNameModelRole, "appName");
|
names.insert(AppNameModelRole, "appName");
|
||||||
|
names.insert(IdModelRole, "notificationId");
|
||||||
names.insert(DismissableModelRole, "dismissable");
|
names.insert(DismissableModelRole, "dismissable");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +156,7 @@ QVariant NotificationsModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
NotificationDbusInterface* notification = m_notificationList[index.row()];
|
NotificationDbusInterface* notification = m_notificationList[index.row()];
|
||||||
|
|
||||||
//FIXME: This function gets called lots of times, producing lots of dbus calls. Add a cache.
|
//FIXME: This function gets called lots of times, producing lots of dbus calls. Add a cache?
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case IconModelRole:
|
case IconModelRole:
|
||||||
return QIcon::fromTheme("device-notifier").pixmap(32, 32);
|
return QIcon::fromTheme("device-notifier").pixmap(32, 32);
|
||||||
|
|
|
@ -38,13 +38,13 @@ class KDECONNECTINTERFACES_EXPORT NotificationsModel
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ModelRoles {
|
enum ModelRoles {
|
||||||
IconModelRole = Qt::DecorationRole,
|
IconModelRole = Qt::DecorationRole,
|
||||||
NameModelRole = Qt::DisplayRole,
|
NameModelRole = Qt::DisplayRole,
|
||||||
ContentModelRole = Qt::UserRole,
|
ContentModelRole = Qt::UserRole,
|
||||||
AppNameModelRole = Qt::UserRole + 1,
|
AppNameModelRole = Qt::UserRole + 1,
|
||||||
IdModelRole = Qt::UserRole + 2,
|
IdModelRole,
|
||||||
DismissableModelRole = Qt::UserRole + 3,
|
DismissableModelRole,
|
||||||
DbusInterfaceRole = Qt::UserRole + 4
|
DbusInterfaceRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationsModel(QObject* parent = 0);
|
NotificationsModel(QObject* parent = 0);
|
||||||
|
|
|
@ -81,6 +81,6 @@ X-KDE-Keywords[sk]=Sieť,Android,Zariadenia
|
||||||
X-KDE-Keywords[sv]=Nätverk, Android, apparater
|
X-KDE-Keywords[sv]=Nätverk, Android, apparater
|
||||||
X-KDE-Keywords[tr]=Ağ,Android,Cihazlar,Aygıtlar
|
X-KDE-Keywords[tr]=Ağ,Android,Cihazlar,Aygıtlar
|
||||||
X-KDE-Keywords[uk]=Network,Android,Devices,мережа,андроїд,пристрої
|
X-KDE-Keywords[uk]=Network,Android,Devices,мережа,андроїд,пристрої
|
||||||
X-KDE-Keywords[x-test]=xxNetwork,Android,Devicesxx
|
X-KDE-Keywords[x-test]=xxNetworkxx,xxAndroidxx,xxDevicesxx
|
||||||
|
|
||||||
Categories=Qt;KDE;X-KDE-settings-kdeconnect;
|
Categories=Qt;KDE;X-KDE-settings-kdeconnect;
|
||||||
|
|
|
@ -43,3 +43,4 @@ void Notification::dismiss()
|
||||||
Q_EMIT dismissRequested(this);
|
Q_EMIT dismissRequested(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ X-KDE-PluginInfo-EnabledByDefault=false
|
||||||
Icon=preferences-desktop-screensaver
|
Icon=preferences-desktop-screensaver
|
||||||
Name=Inhibit screensaver
|
Name=Inhibit screensaver
|
||||||
Name[ca]=Inhibeix l'estalvi de pantalla
|
Name[ca]=Inhibeix l'estalvi de pantalla
|
||||||
|
Name[cs]=Potlačit spořič
|
||||||
Name[es]=Inhibir salvapantallas
|
Name[es]=Inhibir salvapantallas
|
||||||
Name[fi]=Estä näytönsäästäjän käynnistyminen
|
Name[fi]=Estä näytönsäästäjän käynnistyminen
|
||||||
Name[ko]=화면 보호기 막기
|
Name[ko]=화면 보호기 막기
|
||||||
|
@ -26,6 +27,7 @@ Name[uk]=Заборона зберігача екрана
|
||||||
Name[x-test]=xxInhibit screensaverxx
|
Name[x-test]=xxInhibit screensaverxx
|
||||||
Comment=Inhibit the screensaver when the device is connected
|
Comment=Inhibit the screensaver when the device is connected
|
||||||
Comment[ca]=Inhibeix l'estalvi de pantalla quan es connecta el dispositiu
|
Comment[ca]=Inhibeix l'estalvi de pantalla quan es connecta el dispositiu
|
||||||
|
Comment[cs]=Potlačit spořič pokud je zařízení připojeno
|
||||||
Comment[es]=Inhibir el salvapantallas cuando el dispositivo está conectado
|
Comment[es]=Inhibir el salvapantallas cuando el dispositivo está conectado
|
||||||
Comment[fi]=Estä näytönsäästäjän käynnistyminen, kun laite on yhteydessä
|
Comment[fi]=Estä näytönsäästäjän käynnistyminen, kun laite on yhteydessä
|
||||||
Comment[ko]=장치가 연결되어 있을 때 화면 보호기 실행 막기
|
Comment[ko]=장치가 연결되어 있을 때 화면 보호기 실행 막기
|
||||||
|
|
|
@ -57,6 +57,7 @@ SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
|
||||||
: KdeConnectPlugin(parent, args)
|
: KdeConnectPlugin(parent, args)
|
||||||
, m_d(new Pimpl())
|
, m_d(new Pimpl())
|
||||||
{
|
{
|
||||||
|
deviceId = device()->id();
|
||||||
addToDolphin();
|
addToDolphin();
|
||||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Created device:" << device()->name();
|
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Created device:" << device()->name();
|
||||||
}
|
}
|
||||||
|
@ -71,14 +72,14 @@ SftpPlugin::~SftpPlugin()
|
||||||
void SftpPlugin::addToDolphin()
|
void SftpPlugin::addToDolphin()
|
||||||
{
|
{
|
||||||
removeFromDolphin();
|
removeFromDolphin();
|
||||||
QUrl kioUrl("kdeconnect://"+device()->id()+"/");
|
QUrl kioUrl("kdeconnect://"+deviceId+"/");
|
||||||
m_d->placesModel.addPlace(device()->name(), kioUrl, "kdeconnect");
|
m_d->placesModel.addPlace(device()->name(), kioUrl, "kdeconnect");
|
||||||
qCDebug(KDECONNECT_PLUGIN_SFTP) << "add to dolphin";
|
qCDebug(KDECONNECT_PLUGIN_SFTP) << "add to dolphin";
|
||||||
}
|
}
|
||||||
|
|
||||||
void SftpPlugin::removeFromDolphin()
|
void SftpPlugin::removeFromDolphin()
|
||||||
{
|
{
|
||||||
QUrl kioUrl("kdeconnect://"+device()->id()+"/");
|
QUrl kioUrl("kdeconnect://"+deviceId+"/");
|
||||||
QModelIndex index = m_d->placesModel.closestItem(kioUrl);
|
QModelIndex index = m_d->placesModel.closestItem(kioUrl);
|
||||||
while (index.row() != -1) {
|
while (index.row() != -1) {
|
||||||
m_d->placesModel.removePlace(index);
|
m_d->placesModel.removePlace(index);
|
||||||
|
@ -135,7 +136,7 @@ bool SftpPlugin::startBrowsing()
|
||||||
{
|
{
|
||||||
if (mountAndWait()) {
|
if (mountAndWait()) {
|
||||||
//return new KRun(QUrl::fromLocalFile(mountPoint()), 0);
|
//return new KRun(QUrl::fromLocalFile(mountPoint()), 0);
|
||||||
return new KRun(QUrl("kdeconnect://"+device()->id()), 0);
|
return new KRun(QUrl("kdeconnect://"+deviceId), 0);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,7 +169,7 @@ bool SftpPlugin::receivePackage(const NetworkPackage& np)
|
||||||
QString SftpPlugin::mountPoint()
|
QString SftpPlugin::mountPoint()
|
||||||
{
|
{
|
||||||
const QString mountDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
const QString mountDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
|
||||||
return QDir(mountDir).absoluteFilePath(device()->id());
|
return QDir(mountDir).absoluteFilePath(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SftpPlugin::onMounted()
|
void SftpPlugin::onMounted()
|
||||||
|
|
|
@ -62,7 +62,7 @@ private Q_SLOTS:
|
||||||
void onFailed(const QString& message);
|
void onFailed(const QString& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/sftp"; }
|
QString dbusPath() const { return "/modules/kdeconnect/devices/" + deviceId + "/sftp"; }
|
||||||
void knotify(int type, const QString& text, const QPixmap& icon) const;
|
void knotify(int type, const QString& text, const QPixmap& icon) const;
|
||||||
void addToDolphin();
|
void addToDolphin();
|
||||||
void removeFromDolphin();
|
void removeFromDolphin();
|
||||||
|
@ -70,6 +70,7 @@ private:
|
||||||
private:
|
private:
|
||||||
struct Pimpl;
|
struct Pimpl;
|
||||||
QScopedPointer<Pimpl> m_d;
|
QScopedPointer<Pimpl> m_d;
|
||||||
|
QString deviceId; //Storing it to avoid accessing device() from the destructor which could cause a crash
|
||||||
|
|
||||||
QVariantMap remoteDirectories; //Actually a QMap<String, String>, but QDBus preffers this
|
QVariantMap remoteDirectories; //Actually a QMap<String, String>, but QDBus preffers this
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue