Commit 39fed271 authored by Laurent Montel's avatar Laurent Montel 😁

Extract storageservicetreewidgetitem

parent f2e0ab05
......@@ -85,6 +85,7 @@ set(libpimcommon_storageservice_SRCS
storageservice/widgets/storageservicetreewidget.cpp
storageservice/widgets/storageserviceprogresswidget.cpp
storageservice/widgets/storageserviceprogressindicator.cpp
storageservice/widgets/storageservicetreewidgetitem.cpp
storageservice/settings/storageservicesettings.cpp
......
......@@ -17,6 +17,7 @@
#include "boxstorageservice.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/storageservicemanager.h"
#include "boxutil.h"
#include "boxjob.h"
......
......@@ -18,6 +18,7 @@
#include "storageservicedeletedialog.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/widgets/storageserviceprogresswidget.h"
#include "storageservice/widgets/storageserviceprogressindicator.h"
#include "storageservice/storageserviceabstract.h"
......
......@@ -17,6 +17,8 @@
#include "storageservicedownloaddialog.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/widgets/storageserviceprogresswidget.h"
#include "storageservice/widgets/storageserviceprogressindicator.h"
#include "storageservice/storageserviceabstract.h"
......
......@@ -17,6 +17,7 @@
#include "dropboxstorageservice.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/storageservicemanager.h"
#include "dropboxutil.h"
#include "dropboxjob.h"
......
......@@ -17,6 +17,7 @@
#include "gdrivestorageservice.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/storageservicemanager.h"
#include "gdrivejob.h"
#include "storageservice/settings/storageservicesettings.h"
......
......@@ -19,6 +19,7 @@
#include "pimcommon/storageservice/utils/storageserviceutils.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/storageservicemanager.h"
#include "storageservice/settings/storageservicesettings.h"
#include "storageservice/webdav/protocol/webdav_url_info.h"
......
......@@ -21,6 +21,7 @@
#include "storageservicetreewidget.h"
#include "storageservice/storageserviceabstract.h"
#include "storageservice/dialog/storageservicepropertiesdialog.h"
#include "storageservicetreewidgetitem.h"
#include <KIcon>
#include <KLocalizedString>
......@@ -245,127 +246,6 @@ void StorageServiceTreeWidget::slotProperties()
}
}
StorageServiceTreeWidgetItem::StorageServiceTreeWidgetItem(StorageServiceTreeWidget *parent)
: QTreeWidgetItem(parent),
mSize(-1)
{
}
bool StorageServiceTreeWidgetItem::operator<(const QTreeWidgetItem &other) const
{
const QTreeWidgetItem *otherItem = &other;
const StorageServiceTreeWidgetItem *storageItem = static_cast<const StorageServiceTreeWidgetItem*>( otherItem );
StorageServiceTreeWidget::ItemType sourceType = static_cast<StorageServiceTreeWidget::ItemType>(data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::ElementType).toInt());
StorageServiceTreeWidget::ItemType otherType = static_cast<StorageServiceTreeWidget::ItemType>(other.data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::ElementType).toInt());
if (sourceType == StorageServiceTreeWidget::MoveUpType) {
return false;
} else if (otherType == StorageServiceTreeWidget::MoveUpType) {
return false;
}
switch(treeWidget()->sortColumn()) {
case StorageServiceTreeWidget::ColumnName: {
if (sourceType == otherType) {
return text(StorageServiceTreeWidget::ColumnName) < other.text(StorageServiceTreeWidget::ColumnName);
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnSize: {
if (sourceType == otherType) {
return size() < storageItem->size();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnCreated: {
if (sourceType == otherType) {
return createDate() < storageItem->createDate();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnLastModification: {
if (sourceType == otherType) {
return lastModificationDate() < storageItem->lastModificationDate();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
}
return QTreeWidgetItem::operator < ( other );
}
void StorageServiceTreeWidgetItem::setSize(qulonglong size)
{
if (mSize != size) {
mSize = size;
setText(StorageServiceTreeWidget::ColumnSize, KGlobal::locale()->formatByteSize(mSize));
}
}
void StorageServiceTreeWidgetItem::setDateCreated(const KDateTime &date)
{
if (date != mCreateDate) {
mCreateDate = date;
setText(StorageServiceTreeWidget::ColumnCreated, KGlobal::locale()->formatDateTime(mCreateDate));
}
}
void StorageServiceTreeWidgetItem::setLastModification(const KDateTime &date)
{
if (date != mLastModificationDate) {
mLastModificationDate = date;
setText(StorageServiceTreeWidget::ColumnLastModification, KGlobal::locale()->formatDateTime(mLastModificationDate));
}
}
void StorageServiceTreeWidgetItem::setStoreInfo(const QVariantMap &data)
{
setData(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::Info, data);
}
QVariantMap StorageServiceTreeWidgetItem::storeInfo() const
{
return data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::Info).value<QVariantMap>();
}
KDateTime StorageServiceTreeWidgetItem::lastModificationDate() const
{
return mLastModificationDate;
}
KDateTime StorageServiceTreeWidgetItem::createDate() const
{
return mCreateDate;
}
qulonglong StorageServiceTreeWidgetItem::size() const
{
return mSize;
}
......
......@@ -26,30 +26,8 @@
#include "pimcommon_export.h"
class KMenu;
namespace PimCommon {
class StorageServiceTreeWidget;
class StorageServiceAbstract;
class PIMCOMMON_EXPORT StorageServiceTreeWidgetItem : public QTreeWidgetItem
{
public:
StorageServiceTreeWidgetItem(StorageServiceTreeWidget *parent);
bool operator<(const QTreeWidgetItem &other) const;
void setSize(qulonglong size);
void setDateCreated(const KDateTime &date);
void setLastModification(const KDateTime &date);
void setStoreInfo(const QVariantMap &data);
QVariantMap storeInfo() const;
KDateTime lastModificationDate() const;
KDateTime createDate() const;
qulonglong size() const;
private:
KDateTime mCreateDate;
KDateTime mLastModificationDate;
qulonglong mSize;
};
class StorageServiceTreeWidgetItem;
class PIMCOMMON_EXPORT StorageServiceTreeWidget : public QTreeWidget
{
Q_OBJECT
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "storageservicetreewidgetitem.h"
#include "storageservicetreewidget.h"
#include <KGlobal>
#include <KLocale>
using namespace PimCommon;
StorageServiceTreeWidgetItem::StorageServiceTreeWidgetItem(StorageServiceTreeWidget *parent)
: QTreeWidgetItem(parent),
mSize(-1)
{
}
bool StorageServiceTreeWidgetItem::operator<(const QTreeWidgetItem &other) const
{
const QTreeWidgetItem *otherItem = &other;
const StorageServiceTreeWidgetItem *storageItem = static_cast<const StorageServiceTreeWidgetItem*>( otherItem );
StorageServiceTreeWidget::ItemType sourceType = static_cast<StorageServiceTreeWidget::ItemType>(data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::ElementType).toInt());
StorageServiceTreeWidget::ItemType otherType = static_cast<StorageServiceTreeWidget::ItemType>(other.data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::ElementType).toInt());
if (sourceType == StorageServiceTreeWidget::MoveUpType) {
return false;
} else if (otherType == StorageServiceTreeWidget::MoveUpType) {
return false;
}
switch(treeWidget()->sortColumn()) {
case StorageServiceTreeWidget::ColumnName: {
if (sourceType == otherType) {
return text(StorageServiceTreeWidget::ColumnName) < other.text(StorageServiceTreeWidget::ColumnName);
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnSize: {
if (sourceType == otherType) {
return size() < storageItem->size();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnCreated: {
if (sourceType == otherType) {
return createDate() < storageItem->createDate();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
case StorageServiceTreeWidget::ColumnLastModification: {
if (sourceType == otherType) {
return lastModificationDate() < storageItem->lastModificationDate();
} else {
if (sourceType == StorageServiceTreeWidget::Folder) {
return false;
} else {
return true;
}
}
break;
}
}
return QTreeWidgetItem::operator < ( other );
}
void StorageServiceTreeWidgetItem::setSize(qulonglong size)
{
if (mSize != size) {
mSize = size;
setText(StorageServiceTreeWidget::ColumnSize, KGlobal::locale()->formatByteSize(mSize));
}
}
void StorageServiceTreeWidgetItem::setDateCreated(const KDateTime &date)
{
if (date != mCreateDate) {
mCreateDate = date;
setText(StorageServiceTreeWidget::ColumnCreated, KGlobal::locale()->formatDateTime(mCreateDate));
}
}
void StorageServiceTreeWidgetItem::setLastModification(const KDateTime &date)
{
if (date != mLastModificationDate) {
mLastModificationDate = date;
setText(StorageServiceTreeWidget::ColumnLastModification, KGlobal::locale()->formatDateTime(mLastModificationDate));
}
}
void StorageServiceTreeWidgetItem::setStoreInfo(const QVariantMap &data)
{
setData(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::Info, data);
}
QVariantMap StorageServiceTreeWidgetItem::storeInfo() const
{
return data(StorageServiceTreeWidget::ColumnName, StorageServiceTreeWidget::Info).value<QVariantMap>();
}
KDateTime StorageServiceTreeWidgetItem::lastModificationDate() const
{
return mLastModificationDate;
}
KDateTime StorageServiceTreeWidgetItem::createDate() const
{
return mCreateDate;
}
qulonglong StorageServiceTreeWidgetItem::size() const
{
return mSize;
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef STORAGESERVICETREEWIDGETITEM_H
#define STORAGESERVICETREEWIDGETITEM_H
#include <QTreeWidget>
#include <KDateTime>
#include "pimcommon_export.h"
namespace PimCommon {
class StorageServiceTreeWidget;
class PIMCOMMON_EXPORT StorageServiceTreeWidgetItem : public QTreeWidgetItem
{
public:
StorageServiceTreeWidgetItem(StorageServiceTreeWidget *parent);
bool operator<(const QTreeWidgetItem &other) const;
void setSize(qulonglong size);
void setDateCreated(const KDateTime &date);
void setLastModification(const KDateTime &date);
void setStoreInfo(const QVariantMap &data);
QVariantMap storeInfo() const;
KDateTime lastModificationDate() const;
KDateTime createDate() const;
qulonglong size() const;
private:
KDateTime mCreateDate;
KDateTime mLastModificationDate;
qulonglong mSize;
};
}
#endif // STORAGESERVICETREEWIDGETITEM_H
......@@ -17,6 +17,7 @@
#include "yousenditstorageservice.h"
#include "storageservice/widgets/storageservicetreewidget.h"
#include "storageservice/widgets/storageservicetreewidgetitem.h"
#include "storageservice/storageservicemanager.h"
#include "storageservice/settings/storageservicesettings.h"
#include "pimcommon/storageservice/storageservicejobconfig.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment