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" #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()); 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);
kDebug(debugArea()) << "FileTransferJob Downloading payload to" << destination; kDebug(debugArea()) << "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;
} }
} }

View file

@ -40,7 +40,7 @@ public:
FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& destination); FileTransferJob(const QSharedPointer<QIODevice>& origin, qint64 size, const KUrl& destination);
virtual void start(); virtual void start();
KUrl destination() const { return mDestination; } KUrl 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;
KUrl mDestination; KUrl mDestination;
QTime m_time; QTime mTime;
qulonglong m_speedBytes; qulonglong mSpeedBytes;
qint64 mSize; qint64 mSize;
qint64 mWritten; qint64 mWritten;
}; };
#endif #endif

View file

@ -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 {

View file

@ -48,9 +48,9 @@ NotificationsModel::NotificationsModel(QObject* parent)
//Role names for QML //Role names for QML
QHash<int, QByteArray> names = roleNames(); QHash<int, QByteArray> names = roleNames();
names.insert(DbusInterfaceRole, "dbusInterface"); names.insert(DbusInterfaceRole, "dbusInterface");
names.insert(AppNameModelRole, "appName"); names.insert(AppNameModelRole, "appName");
names.insert(IdModelRole, "notificationId"); names.insert(IdModelRole, "notificationId");
names.insert(DismissableModelRole, "dismissable"); names.insert(DismissableModelRole, "dismissable");
setRoleNames(names); setRoleNames(names);
@ -155,7 +155,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 KIcon("device-notifier").pixmap(32, 32); return KIcon("device-notifier").pixmap(32, 32);

View file

@ -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);

View file

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

View file

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