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

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() {
QWidget *lDriveDestWidget = new QWidget;
lDriveDestWidget->setVisible(false);
connect(mDriveSelection, SIGNAL(driveIsSelectedChanged(bool)), lDriveDestWidget, SLOT(setVisible(bool)));
connect(mSyncedRadio, SIGNAL(toggled(bool)), mDriveSelection, SLOT(updateSyncWarning(bool)));
QGridLayout *lDriveVLayout = new QGridLayout;
lDriveVLayout->setColumnMinimumWidth(0, lIndentation);
......
......@@ -42,7 +42,7 @@ bool deviceLessThan(const Solid::Device &a, const Solid::Device &b) {
}
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"),
SIGNAL(selectedDriveChanged(QString)));
......@@ -51,6 +51,7 @@ DriveSelection::DriveSelection(BackupPlan *pBackupPlan, QWidget *parent)
setModel(mDrivesModel);
setItemDelegate(new DriveSelectionDelegate(this));
setSelectionMode(QAbstractItemView::SingleSelection);
setWordWrap(true);
if(!mBackupPlan->mExternalUUID.isEmpty()) {
QStandardItem *lItem = new QStandardItem();
......@@ -158,6 +159,12 @@ void DriveSelection::delayedDeviceAdded() {
lItem->setData(lVolumeDevice.udi(), DriveSelection::UDI);
lItem->setData(lPartitionNumber, DriveSelection::PartitionNumber);
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>();
connect(lAccess, SIGNAL(accessibilityChanged(bool,QString)), SLOT(accessabilityChanged(bool,QString)));
......@@ -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,
QStandardItem **pReturnedItem) const {
for(int lRow = 0; lRow < mDrivesModel->rowCount(); ++lRow) {
......
......@@ -44,7 +44,10 @@ public:
Label,
DeviceDescription,
PartitionNumber,
PartitionsOnDrive
PartitionsOnDrive,
FileSystem,
PermissionLossWarning,
SymlinkLossWarning
};
public:
......@@ -57,6 +60,7 @@ public:
public slots:
void setSelectedDrive(const QString &pUuid);
void saveExtraData();
void updateSyncWarning(bool pSyncBackupSelected);
signals:
void selectedDriveChanged(const QString &pSelectedDrive);
......@@ -79,6 +83,7 @@ protected:
BackupPlan *mBackupPlan;
QStringList mDrivesToAdd;
bool mSelectedAndAccessible;
bool mSyncedBackupType;
};
#endif
......@@ -27,13 +27,15 @@
#include <QStyle>
#include <kcapacitybar.h>
#include <KIcon>
#include <KIconLoader>
#include <KLocale>
#include <kio/global.h>
static const int cMargin = 6;
DriveSelectionDelegate::DriveSelectionDelegate(QObject *pParent)
: QStyledItemDelegate(pParent)
DriveSelectionDelegate::DriveSelectionDelegate(QListView *pParent)
: QStyledItemDelegate(pParent), mListView(pParent)
{
mCapacityBar = new KCapacityBar(KCapacityBar::DrawTextInline);
}
......@@ -57,7 +59,9 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte
}
mCapacityBar->drawCapacityBar(pPainter, pOption.rect.adjusted(cMargin,
cMargin+QApplication::fontMetrics().height()+cMargin,
-cMargin, -cMargin));
-cMargin,
4*cMargin + QApplication::fontMetrics().height() -
pOption.rect.height()));
if (pOption.state & QStyle::State_Selected)
pPainter->setPen(pOption.palette.color(QPalette::HighlightedText));
......@@ -100,13 +104,53 @@ void DriveSelectionDelegate::paint(QPainter* pPainter, const QStyleOptionViewIte
}
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();
}
QSize DriveSelectionDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
Q_UNUSED(option)
QSize size;
size.setHeight(cMargin*5 + QApplication::fontMetrics().height());
size.setWidth(cMargin*2 + QApplication::fontMetrics().width(index.data().toString()));
return size;
QSize DriveSelectionDelegate::sizeHint(const QStyleOptionViewItem& pOption, const QModelIndex& pIndex) const {
Q_UNUSED(pOption)
QSize lSize;
lSize.setWidth(cMargin*2 + QApplication::fontMetrics().width(pIndex.data().toString()));
lSize.setHeight(cMargin*5 + QApplication::fontMetrics().height());
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 @@
#include <QStyledItemDelegate>
class QListView;
class KCapacityBar;
class DriveSelectionDelegate : public QStyledItemDelegate
{
public:
DriveSelectionDelegate(QObject *pParent = 0);
DriveSelectionDelegate(QListView *pParent);
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:
QRect warningRect(const QRect &pRect, const QModelIndex &pIndex) const;
QString warningText(const QModelIndex &pIndex) const;
KCapacityBar *mCapacityBar;
QListView *mListView;
};
#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