Commit 69f2447e authored by Simon Persson's avatar Simon Persson
Browse files

Add a warning that there will be data loss with rsync to fat32/ntfs drives

Fixes #5.
parent a52db594
...@@ -365,6 +365,7 @@ KPageWidgetItem *BackupPlanWidget::createDestinationPage() { ...@@ -365,6 +365,7 @@ KPageWidgetItem *BackupPlanWidget::createDestinationPage() {
QWidget *lDriveDestWidget = new QWidget; QWidget *lDriveDestWidget = new QWidget;
lDriveDestWidget->setVisible(false); lDriveDestWidget->setVisible(false);
connect(mDriveSelection, SIGNAL(driveIsSelectedChanged(bool)), lDriveDestWidget, SLOT(setVisible(bool))); connect(mDriveSelection, SIGNAL(driveIsSelectedChanged(bool)), lDriveDestWidget, SLOT(setVisible(bool)));
connect(mSyncedRadio, SIGNAL(toggled(bool)), mDriveSelection, SLOT(updateSyncWarning(bool)));
QGridLayout *lDriveVLayout = new QGridLayout; QGridLayout *lDriveVLayout = new QGridLayout;
lDriveVLayout->setColumnMinimumWidth(0, lIndentation); lDriveVLayout->setColumnMinimumWidth(0, lIndentation);
......
...@@ -42,7 +42,7 @@ bool deviceLessThan(const Solid::Device &a, const Solid::Device &b) { ...@@ -42,7 +42,7 @@ bool deviceLessThan(const Solid::Device &a, const Solid::Device &b) {
} }
DriveSelection::DriveSelection(BackupPlan *pBackupPlan, QWidget *parent) DriveSelection::DriveSelection(BackupPlan *pBackupPlan, QWidget *parent)
: QListView(parent), mBackupPlan(pBackupPlan), mSelectedAndAccessible(false) : QListView(parent), mBackupPlan(pBackupPlan), mSelectedAndAccessible(false), mSyncedBackupType(false)
{ {
KConfigDialogManager::changedMap()->insert(QLatin1String("DriveSelection"), KConfigDialogManager::changedMap()->insert(QLatin1String("DriveSelection"),
SIGNAL(selectedDriveChanged(QString))); SIGNAL(selectedDriveChanged(QString)));
...@@ -51,6 +51,7 @@ DriveSelection::DriveSelection(BackupPlan *pBackupPlan, QWidget *parent) ...@@ -51,6 +51,7 @@ DriveSelection::DriveSelection(BackupPlan *pBackupPlan, QWidget *parent)
setModel(mDrivesModel); setModel(mDrivesModel);
setItemDelegate(new DriveSelectionDelegate(this)); setItemDelegate(new DriveSelectionDelegate(this));
setSelectionMode(QAbstractItemView::SingleSelection); setSelectionMode(QAbstractItemView::SingleSelection);
setWordWrap(true);
if(!mBackupPlan->mExternalUUID.isEmpty()) { if(!mBackupPlan->mExternalUUID.isEmpty()) {
QStandardItem *lItem = new QStandardItem(); QStandardItem *lItem = new QStandardItem();
...@@ -158,6 +159,12 @@ void DriveSelection::delayedDeviceAdded() { ...@@ -158,6 +159,12 @@ void DriveSelection::delayedDeviceAdded() {
lItem->setData(lVolumeDevice.udi(), DriveSelection::UDI); lItem->setData(lVolumeDevice.udi(), DriveSelection::UDI);
lItem->setData(lPartitionNumber, DriveSelection::PartitionNumber); lItem->setData(lPartitionNumber, DriveSelection::PartitionNumber);
lItem->setData(lVolumeDeviceList.count(), DriveSelection::PartitionsOnDrive); lItem->setData(lVolumeDeviceList.count(), DriveSelection::PartitionsOnDrive);
lItem->setData(lVolume->fsType(), DriveSelection::FileSystem);
lItem->setData(mSyncedBackupType && (lVolume->fsType() == QLatin1String("vfat") ||
lVolume->fsType() == QLatin1String("ntfs")),
DriveSelection::PermissionLossWarning);
lItem->setData(mSyncedBackupType && lVolume->fsType() == QLatin1String("vfat"),
DriveSelection::SymlinkLossWarning);
Solid::StorageAccess *lAccess = lVolumeDevice.as<Solid::StorageAccess>(); Solid::StorageAccess *lAccess = lVolumeDevice.as<Solid::StorageAccess>();
connect(lAccess, SIGNAL(accessibilityChanged(bool,QString)), SLOT(accessabilityChanged(bool,QString))); connect(lAccess, SIGNAL(accessibilityChanged(bool,QString)), SLOT(accessabilityChanged(bool,QString)));
...@@ -295,6 +302,18 @@ void DriveSelection::saveExtraData() { ...@@ -295,6 +302,18 @@ void DriveSelection::saveExtraData() {
} }
} }
void DriveSelection::updateSyncWarning(bool pSyncBackupSelected) {
mSyncedBackupType = pSyncBackupSelected;
for(int i = 0; i < mDrivesModel->rowCount(); ++i) {
QString lFsType = mDrivesModel->item(i)->data(DriveSelection::FileSystem).toString();
mDrivesModel->item(i)->setData(mSyncedBackupType && (lFsType == QLatin1String("vfat") ||
lFsType == QLatin1String("ntfs")),
DriveSelection::PermissionLossWarning);
mDrivesModel->item(i)->setData(mSyncedBackupType && lFsType == QLatin1String("vfat"),
DriveSelection::SymlinkLossWarning);
}
}
int DriveSelection::findItem(const DriveSelection::DataType pField, const QString &pSearchString, int DriveSelection::findItem(const DriveSelection::DataType pField, const QString &pSearchString,
QStandardItem **pReturnedItem) const { QStandardItem **pReturnedItem) const {
for(int lRow = 0; lRow < mDrivesModel->rowCount(); ++lRow) { for(int lRow = 0; lRow < mDrivesModel->rowCount(); ++lRow) {
......
...@@ -44,7 +44,10 @@ public: ...@@ -44,7 +44,10 @@ public:
Label, Label,
DeviceDescription, DeviceDescription,
PartitionNumber, PartitionNumber,
PartitionsOnDrive PartitionsOnDrive,
FileSystem,
PermissionLossWarning,
SymlinkLossWarning
}; };
public: public:
...@@ -57,6 +60,7 @@ public: ...@@ -57,6 +60,7 @@ public:
public slots: public slots:
void setSelectedDrive(const QString &pUuid); void setSelectedDrive(const QString &pUuid);
void saveExtraData(); void saveExtraData();
void updateSyncWarning(bool pSyncBackupSelected);
signals: signals:
void selectedDriveChanged(const QString &pSelectedDrive); void selectedDriveChanged(const QString &pSelectedDrive);
...@@ -79,6 +83,7 @@ protected: ...@@ -79,6 +83,7 @@ protected:
BackupPlan *mBackupPlan; BackupPlan *mBackupPlan;
QStringList mDrivesToAdd; QStringList mDrivesToAdd;
bool mSelectedAndAccessible; bool mSelectedAndAccessible;
bool mSyncedBackupType;
}; };
#endif #endif
...@@ -27,13 +27,15 @@ ...@@ -27,13 +27,15 @@
#include <QStyle> #include <QStyle>
#include <kcapacitybar.h> #include <kcapacitybar.h>
#include <KIcon>
#include <KIconLoader>
#include <KLocale> #include <KLocale>
#include <kio/global.h> #include <kio/global.h>
static const int cMargin = 6; static const int cMargin = 6;
DriveSelectionDelegate::DriveSelectionDelegate(QObject *pParent) DriveSelectionDelegate::DriveSelectionDelegate(QListView *pParent)
: QStyledItemDelegate(pParent) : QStyledItemDelegate(pParent), mListView(pParent)
{ {
mCapacityBar = new KCapacityBar(KCapacityBar::DrawTextInline); mCapacityBar = new KCapacityBar(KCapacityBar::DrawTextInline);
} }
...@@ -57,7 +59,9 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte ...@@ -57,7 +59,9 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte
} }
mCapacityBar->drawCapacityBar(pPainter, pOption.rect.adjusted(cMargin, mCapacityBar->drawCapacityBar(pPainter, pOption.rect.adjusted(cMargin,
cMargin+QApplication::fontMetrics().height()+cMargin, cMargin+QApplication::fontMetrics().height()+cMargin,
-cMargin, -cMargin)); -cMargin,
4*cMargin + QApplication::fontMetrics().height() -
pOption.rect.height()));
if (pOption.state & QStyle::State_Selected) if (pOption.state & QStyle::State_Selected)
pPainter->setPen(pOption.palette.color(QPalette::HighlightedText)); pPainter->setPen(pOption.palette.color(QPalette::HighlightedText));
...@@ -100,13 +104,53 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte ...@@ -100,13 +104,53 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte
} }
pPainter->drawText(pOption.rect.topLeft() + QPoint(cMargin, cMargin+QApplication::fontMetrics().height()), lDisplayLabel); pPainter->drawText(pOption.rect.topLeft() + QPoint(cMargin, cMargin+QApplication::fontMetrics().height()), lDisplayLabel);
int lIconSize = KIconLoader::SizeLarge;
QRect lWarningRect = warningRect(pOption.rect.adjusted(lIconSize + cMargin, 0, 0, 0), pIndex);
if(!lWarningRect.isEmpty()) {
KIcon lIcon(QLatin1String("dialog-warning"));
lIcon.paint(pPainter, lWarningRect.left() - cMargin - lIconSize, lWarningRect.top(), lIconSize, lIconSize);
pPainter->drawText(lWarningRect, Qt::AlignVCenter | Qt::TextWordWrap, warningText(pIndex));
}
pPainter->restore(); pPainter->restore();
} }
QSize DriveSelectionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const { QSize DriveSelectionDelegate::sizeHint(const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const {
Q_UNUSED(option) Q_UNUSED(pOption)
QSize size; QSize lSize;
size.setHeight(cMargin*5 + QApplication::fontMetrics().height()); lSize.setWidth(cMargin*2 + QApplication::fontMetrics().width(pIndex.data().toString()));
size.setWidth(cMargin*2 + QApplication::fontMetrics().width(index.data().toString())); lSize.setHeight(cMargin*5 + QApplication::fontMetrics().height());
return size; QRect lWarningRect = warningRect(mListView->rect().adjusted(KIconLoader::SizeLarge + cMargin, 0, 0, 0), pIndex);
if(!lWarningRect.isEmpty()) {
lSize.setHeight(lSize.height() + 2*cMargin + lWarningRect.height());
}
return lSize;
}
QRect DriveSelectionDelegate::warningRect(const QRect &pRect, const QModelIndex &pIndex) const {
QRect lTextLocation = pRect.adjusted(cMargin, 5*cMargin + QApplication::fontMetrics().height(), -cMargin, -cMargin);
QString lWarningText = warningText(pIndex);
if(lWarningText.isEmpty()) {
return QRect();
}
QRect lTextBoundary = QApplication::fontMetrics().boundingRect(lTextLocation, Qt::TextWordWrap, lWarningText);
if(lTextBoundary.height() < KIconLoader::SizeLarge) {
lTextBoundary.setHeight(KIconLoader::SizeLarge);
}
return lTextBoundary;
}
QString DriveSelectionDelegate::warningText(const QModelIndex &pIndex) const {
bool lPermissionWarning = pIndex.data(DriveSelection::PermissionLossWarning).toBool();
bool lSymlinkWarning = pIndex.data(DriveSelection::SymlinkLossWarning).toBool();
if(lPermissionWarning && lSymlinkWarning) {
return i18nc("@item:inlistbox", "Warning: Symbolic links and file permissions can not be saved "
"to this file system. File permissions only matters if there is more than one "
"user of this computer or if you are backing up executable program files.");
} else if(lPermissionWarning) {
return i18nc("@item:inlistbox", "Warning: File permissions can not be saved to this file "
"system. File permissions only matters if there is more than one "
"user of this computer or if you are backing up executable program files.");
}
return QString();
} }
...@@ -23,16 +23,20 @@ ...@@ -23,16 +23,20 @@
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
class QListView;
class KCapacityBar; class KCapacityBar;
class DriveSelectionDelegate : public QStyledItemDelegate class DriveSelectionDelegate : public QStyledItemDelegate
{ {
public: public:
DriveSelectionDelegate(QObject *pParent = 0); DriveSelectionDelegate(QListView *pParent);
virtual void paint(QPainter* pPainter, const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const; virtual void paint(QPainter* pPainter, const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const;
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; virtual QSize sizeHint(const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const;
private: private:
QRect warningRect(const QRect &pRect, const QModelIndex &pIndex) const;
QString warningText(const QModelIndex &pIndex) const;
KCapacityBar *mCapacityBar; KCapacityBar *mCapacityBar;
QListView *mListView;
}; };
#endif // DRIVESELECTIONDELEGATE_H #endif // DRIVESELECTIONDELEGATE_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