Re: [linux-minidisc] Implementing downloading in QHiMDTransfer
Am 13.10.2012 14:16, schrieb Kevin Chabowski:
Am 13.10.2012, 13:15 Uhr, schrieb Michael Karcher
<Michael.Karcher@fu-berlin.de>:
In the GUI, I would not consider to offer the user to upload any file
not having a supported extension, i.e. only MP3 at the time being. A
basic MP3 sanity check as discussed above would be a good idea.
Okay, so I will add a file extension check when the download button
should be
unlocked and perhaps try to implement this sanity check in the actual
upload code.
Kevin
Hi Kevin,
i´ve made some changes to include file extension checking in the
FileSystemModel.
Only files with supported extension are allowed to use, other files are
not selectable and not enabled/grayed out in the file browser.
Please take a look at it, maybe this will be committed into the master repo.
Thomas
>From e8d6f6ae50a975d3b097181586b30a6418a2ddd7 Mon Sep 17 00:00:00 2001
From: Thomas Arp <manner.moe@gmx.de>
Date: Sat, 13 Oct 2012 22:16:45 +0200
Subject: [PATCH 1/3] disable unsupported codecs in localbrowser
---
qhimdtransfer/qhimdmainwindow.cpp | 1 +
qhimdtransfer/qhimdmainwindow.h | 3 +--
qhimdtransfer/qhimdmodel.cpp | 14 ++++++++++++++
qhimdtransfer/qhimdmodel.h | 13 +++++++++++++
4 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp
index b79d9a0..72ec8d6 100644
--- a/qhimdtransfer/qhimdmainwindow.cpp
+++ b/qhimdtransfer/qhimdmainwindow.cpp
@@ -237,6 +237,7 @@ void QHiMDMainWindow::init_local_browser()
QStringList DownloadFileList;
localmodel.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
localmodel.setNameFilters(QStringList() << "*.mp3" << "*.wav" << "*.oma");
+ localmodel.enableFiles(trackmodel.supportedCodecs());
localmodel.setNameFilterDisables(false);
localmodel.setReadOnly(false);
localmodel.setRootPath("/");
diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h
index 0ca406f..535b4bb 100644
--- a/qhimdtransfer/qhimdmainwindow.h
+++ b/qhimdtransfer/qhimdmainwindow.h
@@ -4,7 +4,6 @@
#include <QtGui/QMainWindow>
#include <QtGui/QFileDialog>
#include <QtCore/QSettings>
-#include <QtGui/QFileSystemModel>
#include "qhimdaboutdialog.h"
#include "qhimdformatdialog.h"
#include "qhimduploaddialog.h"
@@ -40,7 +39,7 @@ private:
QHiMDUploadDialog * uploadDialog;
QHiMDDetection * detect;
QHiMDTracksModel trackmodel;
- QFileSystemModel localmodel;
+ QHiMDFileSystemModel localmodel;
QSettings settings;
QString dumpmp3(const QHiMDTrack & trk, QString file);
QString dumpoma(const QHiMDTrack & trk, QString file);
diff --git a/qhimdtransfer/qhimdmodel.cpp b/qhimdtransfer/qhimdmodel.cpp
index 541a714..0ac8ee1 100644
--- a/qhimdtransfer/qhimdmodel.cpp
+++ b/qhimdtransfer/qhimdmodel.cpp
@@ -267,3 +267,17 @@ QHiMDTrackList QHiMDTracksModel::tracks(const QModelIndexList & modelindices) co
tracks.append(track(index.row()));
return tracks;
}
+
+/* QFileSystemModel stuff */
+
+Qt::ItemFlags QHiMDFileSystemModel::flags(const QModelIndex &index) const
+{
+ if(!isDir(index) && !supportedFiles.contains((fileInfo(index).suffix()), Qt::CaseInsensitive))
+ return QFileSystemModel::flags(index) & Qt::ItemIsSelectable;
+
+ return QFileSystemModel::flags(index);
+}
+void QHiMDFileSystemModel::enableFiles(QStringList files)
+{
+ supportedFiles = files;
+}
diff --git a/qhimdtransfer/qhimdmodel.h b/qhimdtransfer/qhimdmodel.h
index 8d7e06f..131bf5e 100644
--- a/qhimdtransfer/qhimdmodel.h
+++ b/qhimdtransfer/qhimdmodel.h
@@ -4,6 +4,8 @@
#include <QtCore/QAbstractListModel>
#include <QtCore/QTime>
#include <QtCore/QList>
+#include <QtCore/QStringList>
+#include <QtGui/QFileSystemModel>
#include "himd.h"
#include "sony_oma.h"
@@ -50,6 +52,17 @@ public:
void close();
QHiMDTrack track(int trackidx) const;
QHiMDTrackList tracks(const QModelIndexList & indices) const;
+ QStringList supportedCodecs() { return (QStringList() << "mp3"); } ;
};
+class QHiMDFileSystemModel : public QFileSystemModel {
+ Q_OBJECT
+
+ QStringList supportedFiles;
+public:
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ void enableFiles(QStringList files);
+};
+
+
#endif
--
1.7.11.msysgit.1
>From 2a1cc6738b52c262c3121c71256a82e982cec1cb Mon Sep 17 00:00:00 2001
From: Thomas Arp <manner.moe@gmx.de>
Date: Sat, 13 Oct 2012 22:30:53 +0200
Subject: [PATCH 2/3] some cleanup
---
qhimdtransfer/qhimdmodel.cpp | 6 ++++++
qhimdtransfer/qhimdmodel.h | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/qhimdtransfer/qhimdmodel.cpp b/qhimdtransfer/qhimdmodel.cpp
index 0ac8ee1..4bb383c 100644
--- a/qhimdtransfer/qhimdmodel.cpp
+++ b/qhimdtransfer/qhimdmodel.cpp
@@ -268,6 +268,11 @@ QHiMDTrackList QHiMDTracksModel::tracks(const QModelIndexList & modelindices) co
return tracks;
}
+QStringList QHiMDTracksModel::supportedCodecs()
+{
+ return (QStringList() << "mp3");
+}
+
/* QFileSystemModel stuff */
Qt::ItemFlags QHiMDFileSystemModel::flags(const QModelIndex &index) const
@@ -277,6 +282,7 @@ Qt::ItemFlags QHiMDFileSystemModel::flags(const QModelIndex &index) const
return QFileSystemModel::flags(index);
}
+
void QHiMDFileSystemModel::enableFiles(QStringList files)
{
supportedFiles = files;
diff --git a/qhimdtransfer/qhimdmodel.h b/qhimdtransfer/qhimdmodel.h
index 131bf5e..9f172c9 100644
--- a/qhimdtransfer/qhimdmodel.h
+++ b/qhimdtransfer/qhimdmodel.h
@@ -52,7 +52,7 @@ public:
void close();
QHiMDTrack track(int trackidx) const;
QHiMDTrackList tracks(const QModelIndexList & indices) const;
- QStringList supportedCodecs() { return (QStringList() << "mp3"); } ;
+ QStringList supportedCodecs();
};
class QHiMDFileSystemModel : public QFileSystemModel {
--
1.7.11.msysgit.1
>From d293fe8708c7d9d1647545dd02eb159124ed61fe Mon Sep 17 00:00:00 2001
From: Thomas Arp <manner.moe@gmx.de>
Date: Sun, 14 Oct 2012 00:07:31 +0200
Subject: [PATCH 3/3] some more cleanup and renaming
---
qhimdtransfer/qhimdmainwindow.cpp | 2 +-
qhimdtransfer/qhimdmodel.cpp | 10 +++++-----
qhimdtransfer/qhimdmodel.h | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp
index 72ec8d6..9b35839 100644
--- a/qhimdtransfer/qhimdmainwindow.cpp
+++ b/qhimdtransfer/qhimdmainwindow.cpp
@@ -237,7 +237,7 @@ void QHiMDMainWindow::init_local_browser()
QStringList DownloadFileList;
localmodel.setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot);
localmodel.setNameFilters(QStringList() << "*.mp3" << "*.wav" << "*.oma");
- localmodel.enableFiles(trackmodel.supportedCodecs());
+ localmodel.setSelectableExtensions(trackmodel.downloadableFileExtensions());
localmodel.setNameFilterDisables(false);
localmodel.setReadOnly(false);
localmodel.setRootPath("/");
diff --git a/qhimdtransfer/qhimdmodel.cpp b/qhimdtransfer/qhimdmodel.cpp
index 4bb383c..ac4bde5 100644
--- a/qhimdtransfer/qhimdmodel.cpp
+++ b/qhimdtransfer/qhimdmodel.cpp
@@ -268,7 +268,7 @@ QHiMDTrackList QHiMDTracksModel::tracks(const QModelIndexList & modelindices) co
return tracks;
}
-QStringList QHiMDTracksModel::supportedCodecs()
+QStringList QHiMDTracksModel::downloadableFileExtensions() const
{
return (QStringList() << "mp3");
}
@@ -277,13 +277,13 @@ QStringList QHiMDTracksModel::supportedCodecs()
Qt::ItemFlags QHiMDFileSystemModel::flags(const QModelIndex &index) const
{
- if(!isDir(index) && !supportedFiles.contains((fileInfo(index).suffix()), Qt::CaseInsensitive))
- return QFileSystemModel::flags(index) & Qt::ItemIsSelectable;
+ if(!isDir(index) && !selectableExtensions.contains((fileInfo(index).suffix()), Qt::CaseInsensitive))
+ return Qt::NoItemFlags; //not selectable, not enabled (grayed out in the browser)
return QFileSystemModel::flags(index);
}
-void QHiMDFileSystemModel::enableFiles(QStringList files)
+void QHiMDFileSystemModel::setSelectableExtensions(QStringList extensions)
{
- supportedFiles = files;
+ selectableExtensions = extensions;
}
diff --git a/qhimdtransfer/qhimdmodel.h b/qhimdtransfer/qhimdmodel.h
index 9f172c9..6ccc2f8 100644
--- a/qhimdtransfer/qhimdmodel.h
+++ b/qhimdtransfer/qhimdmodel.h
@@ -52,16 +52,16 @@ public:
void close();
QHiMDTrack track(int trackidx) const;
QHiMDTrackList tracks(const QModelIndexList & indices) const;
- QStringList supportedCodecs();
+ QStringList downloadableFileExtensions() const;
};
class QHiMDFileSystemModel : public QFileSystemModel {
Q_OBJECT
- QStringList supportedFiles;
+ QStringList selectableExtensions;
public:
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
- void enableFiles(QStringList files);
+ void setSelectableExtensions(QStringList extensions);
};
--
1.7.11.msysgit.1