Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
System
Kup
Commits
69f2447e
Commit
69f2447e
authored
May 09, 2014
by
Simon Persson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a warning that there will be data loss with rsync to fat32/ntfs drives
Fixes
#5
.
parent
a52db594
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
13 deletions
+86
-13
kcm/backupplanwidget.cpp
kcm/backupplanwidget.cpp
+1
-0
kcm/driveselection.cpp
kcm/driveselection.cpp
+20
-1
kcm/driveselection.h
kcm/driveselection.h
+6
-1
kcm/driveselectiondelegate.cpp
kcm/driveselectiondelegate.cpp
+53
-9
kcm/driveselectiondelegate.h
kcm/driveselectiondelegate.h
+6
-2
No files found.
kcm/backupplanwidget.cpp
View file @
69f2447e
...
...
@@ -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
);
...
...
kcm/driveselection.cpp
View file @
69f2447e
...
...
@@ -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
)
{
...
...
kcm/driveselection.h
View file @
69f2447e
...
...
@@ -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
kcm/driveselectiondelegate.cpp
View file @
69f2447e
...
...
@@ -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
(
Q
Object
*
pParent
)
:
QStyledItemDelegate
(
pParent
)
DriveSelectionDelegate
::
DriveSelectionDelegate
(
Q
ListView
*
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
();
}
kcm/driveselectiondelegate.h
View file @
69f2447e
...
...
@@ -23,16 +23,20 @@
#include <QStyledItemDelegate>
class
QListView
;
class
KCapacityBar
;
class
DriveSelectionDelegate
:
public
QStyledItemDelegate
{
public:
DriveSelectionDelegate
(
Q
Object
*
pParent
=
0
);
DriveSelectionDelegate
(
Q
ListView
*
pParent
);
virtual
void
paint
(
QPainter
*
pPainter
,
const
QStyleOptionViewItem
&
pOption
,
const
QModelIndex
&
pIndex
)
const
;
virtual
QSize
sizeHint
(
const
QStyleOptionViewItem
&
o
ption
,
const
QModelIndex
&
i
ndex
)
const
;
virtual
QSize
sizeHint
(
const
QStyleOptionViewItem
&
pO
ption
,
const
QModelIndex
&
pI
ndex
)
const
;
private:
QRect
warningRect
(
const
QRect
&
pRect
,
const
QModelIndex
&
pIndex
)
const
;
QString
warningText
(
const
QModelIndex
&
pIndex
)
const
;
KCapacityBar
*
mCapacityBar
;
QListView
*
mListView
;
};
#endif // DRIVESELECTIONDELEGATE_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment