Coding style

This commit is contained in:
Albert Vaca 2015-01-20 22:22:14 -08:00
parent 91d4a03258
commit da1cb4c354
7 changed files with 39 additions and 43 deletions

View file

@ -28,18 +28,17 @@
#include "kdebugnamespace.h"
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& destination): KJob()
FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& 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);
kDebug(debugArea()) << "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 KUrl& destination);
virtual void start();
KUrl 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;
KUrl mDestination;
QTime m_time;
qulonglong m_speedBytes;
QTime mTime;
qulonglong mSpeedBytes;
qint64 mSize;
qint64 mWritten;
};
#endif

View file

@ -155,7 +155,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 KIcon("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

@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANALITZADECLARATIVEPLUGIN_H
#define ANALITZADECLARATIVEPLUGIN_H
#ifndef KDECONNECTDECLARATIVEPLUGIN_H
#define KDECONNECTDECLARATIVEPLUGIN_H
#include <QDeclarativeExtensionPlugin>
@ -30,7 +30,4 @@ class KdeConnectDeclarativePlugin : public QDeclarativeExtensionPlugin
};
#endif // ANALITZADECLARATIVEPLUGIN_H
#endif

View file

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