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:
Albert Vaca 2015-01-20 22:44:31 -08:00
commit 6cc6d287fc
10 changed files with 47 additions and 42 deletions

View file

@ -28,18 +28,17 @@
#include <KIO/RenameDialog>
#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());
//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);
qCDebug(KDECONNECT_CORE) << "FileTransferJob Downloading payload to" << destination;
}
@ -117,14 +116,14 @@ void FileTransferJob::startTransfer()
{
setTotalAmount(Bytes, mSize);
setProcessedAmount(Bytes, 0);
m_time = QTime::currentTime();
mTime = QTime::currentTime();
description(this, i18n("Receiving file over KDE-Connect"),
QPair<QString, QString>(i18nc("File transfer origin", "From"),
QString(mDeviceName)),
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);
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(result(KJob*)), this, SLOT(openFinished(KJob*)));
@ -165,15 +164,15 @@ void FileTransferJob::readyRead()
if (mSize > -1) {
//If a least 1 second has passed since last update
int secondsSinceLastTime = m_time.secsTo(QTime::currentTime());
if (secondsSinceLastTime > 0 && m_speedBytes > 0) {
float speed = (mWritten - m_speedBytes) / secondsSinceLastTime;
int secondsSinceLastTime = mTime.secsTo(QTime::currentTime());
if (secondsSinceLastTime > 0 && mSpeedBytes > 0) {
float speed = (mWritten - mSpeedBytes) / secondsSinceLastTime;
emitSpeed(speed);
m_time = QTime::currentTime();
m_speedBytes = mWritten;
} else if(m_speedBytes == 0) {
m_speedBytes = mWritten;
mTime = QTime::currentTime();
mSpeedBytes = mWritten;
} else if(mSpeedBytes == 0) {
mSpeedBytes = mWritten;
}
}

View file

@ -40,7 +40,7 @@ public:
FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const QUrl &destination);
virtual void start();
QUrl destination() const { return mDestination; }
void setDeviceName(const QString &deviceName) {mDeviceName = deviceName;};
void setDeviceName(const QString &deviceName) { mDeviceName = deviceName; }
public Q_SLOTS:
void doStart();
@ -59,11 +59,10 @@ private:
KIO::FileJob* mDestinationJob;
QString mDeviceName;
QUrl mDestination;
QTime m_time;
qulonglong m_speedBytes;
QTime mTime;
qulonglong mSpeedBytes;
qint64 mSize;
qint64 mWritten;
};
#endif

View file

@ -48,9 +48,11 @@ NotificationsModel::NotificationsModel(QObject* parent)
QHash<int, QByteArray> NotificationsModel::roleNames() const
{
//Role names for QML
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
names.insert(DbusInterfaceRole, "dbusInterface");
names.insert(AppNameModelRole, "appName");
names.insert(IdModelRole, "notificationId");
names.insert(DismissableModelRole, "dismissable");
return names;
}
@ -154,7 +156,7 @@ QVariant NotificationsModel::data(const QModelIndex& index, int role) const
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) {
case IconModelRole:
return QIcon::fromTheme("device-notifier").pixmap(32, 32);

View file

@ -42,9 +42,9 @@ public:
NameModelRole = Qt::DisplayRole,
ContentModelRole = Qt::UserRole,
AppNameModelRole = Qt::UserRole + 1,
IdModelRole = Qt::UserRole + 2,
DismissableModelRole = Qt::UserRole + 3,
DbusInterfaceRole = Qt::UserRole + 4
IdModelRole,
DismissableModelRole,
DbusInterfaceRole,
};
NotificationsModel(QObject* parent = 0);

View file

@ -81,6 +81,6 @@ X-KDE-Keywords[sk]=Sieť,Android,Zariadenia
X-KDE-Keywords[sv]=Nätverk, Android, apparater
X-KDE-Keywords[tr]=Ağ,Android,Cihazlar,Aygıtlar
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;

View file

@ -43,3 +43,4 @@ void Notification::dismiss()
Q_EMIT dismissRequested(this);
}
}

View file

@ -13,6 +13,7 @@ X-KDE-PluginInfo-EnabledByDefault=false
Icon=preferences-desktop-screensaver
Name=Inhibit screensaver
Name[ca]=Inhibeix l'estalvi de pantalla
Name[cs]=Potlačit spořič
Name[es]=Inhibir salvapantallas
Name[fi]=Estä näytönsäästäjän käynnistyminen
Name[ko]=
@ -26,6 +27,7 @@ Name[uk]=Заборона зберігача екрана
Name[x-test]=xxInhibit screensaverxx
Comment=Inhibit the screensaver when the device is connected
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[fi]=Estä näytönsäästäjän käynnistyminen, kun laite on yhteydessä
Comment[ko]=

View file

@ -57,6 +57,7 @@ SftpPlugin::SftpPlugin(QObject *parent, const QVariantList &args)
: KdeConnectPlugin(parent, args)
, m_d(new Pimpl())
{
deviceId = device()->id();
addToDolphin();
qCDebug(KDECONNECT_PLUGIN_SFTP) << "Created device:" << device()->name();
}
@ -71,14 +72,14 @@ SftpPlugin::~SftpPlugin()
void SftpPlugin::addToDolphin()
{
removeFromDolphin();
QUrl kioUrl("kdeconnect://"+device()->id()+"/");
QUrl kioUrl("kdeconnect://"+deviceId+"/");
m_d->placesModel.addPlace(device()->name(), kioUrl, "kdeconnect");
qCDebug(KDECONNECT_PLUGIN_SFTP) << "add to dolphin";
}
void SftpPlugin::removeFromDolphin()
{
QUrl kioUrl("kdeconnect://"+device()->id()+"/");
QUrl kioUrl("kdeconnect://"+deviceId+"/");
QModelIndex index = m_d->placesModel.closestItem(kioUrl);
while (index.row() != -1) {
m_d->placesModel.removePlace(index);
@ -135,7 +136,7 @@ bool SftpPlugin::startBrowsing()
{
if (mountAndWait()) {
//return new KRun(QUrl::fromLocalFile(mountPoint()), 0);
return new KRun(QUrl("kdeconnect://"+device()->id()), 0);
return new KRun(QUrl("kdeconnect://"+deviceId), 0);
}
return false;
}
@ -168,7 +169,7 @@ bool SftpPlugin::receivePackage(const NetworkPackage& np)
QString SftpPlugin::mountPoint()
{
const QString mountDir = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
return QDir(mountDir).absoluteFilePath(device()->id());
return QDir(mountDir).absoluteFilePath(deviceId);
}
void SftpPlugin::onMounted()

View file

@ -62,7 +62,7 @@ private Q_SLOTS:
void onFailed(const QString& message);
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 addToDolphin();
void removeFromDolphin();
@ -70,6 +70,7 @@ private:
private:
struct Pimpl;
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
};