Skip to content

Commit

Permalink
rename from "StorageBookmark" to "Bookmark", and change the Type from…
Browse files Browse the repository at this point in the history
… {Storage / Bookmark} to {System / User}.(refs #79)
  • Loading branch information
haraki committed Jun 15, 2019
1 parent dc40632 commit a3abb85
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 331 deletions.
43 changes: 43 additions & 0 deletions bookmarkinfo.h
@@ -0,0 +1,43 @@
#ifndef BOOKMARKINFO_H
#define BOOKMARKINFO_H

#include <QString>

namespace Farman
{

// ブックマーク情報
class BookmarkInfo
{
public:
enum class Type : int
{
System,
User,
};

BookmarkInfo(Type type, const QString& name, const QString& path)
{
m_type = type;
m_name = name;
m_path = path;
}

~BookmarkInfo() = default;

Type getType() const { return m_type; }
QString getTypeName() const { return (m_type == Type::System) ? "System" : (m_type == Type::User) ? "User" : "Unknown"; }
QString getName() const { return m_name; }
QString getPath() const { return m_path; }

private:
BookmarkInfo() = delete;

Type m_type;
QString m_name;
QString m_path;
};

} // namespace Farman

#endif // BOOKMARKINFO_H
129 changes: 117 additions & 12 deletions bookmarkinfomodel.cpp
@@ -1,18 +1,82 @@
#include "bookmarkinfomodel.h"
#include <QStorageInfo>
#include <QDebug>
#include "settings.h"
#include "bookmarkinfomodel.h"

namespace Farman
{

BookmarkInfoModel::BookmarkInfoModel(QObject *parent)
: QAbstractTableModel(parent)
, m_fileSystemModel(new QFileSystemModel(this))
{
initialize();
}

QVariant BookmarkInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
int BookmarkInfoModel::initialize()
{
// FIXME: Implement me!
qDebug() << "BookmarkInfoModel::initialize()";

m_infos.clear();

for(const QStorageInfo& volume : QStorageInfo::mountedVolumes())
{
qDebug() << "Name : " << volume.name();
qDebug() << "Display Name : " << volume.displayName();
qDebug() << "Device:" << volume.device();
qDebug() << "Root path:" << volume.rootPath();
qDebug() << "File system type:" << volume.fileSystemType();
qDebug() << "Is valid" << volume.isValid();
qDebug() << "Is root" << volume.isRoot();
qDebug() << "Is ready" << volume.isReady();
qDebug() << "Is read only" << volume.isReadOnly();
qDebug() << QString("Bytes available: %L1 Bytes").arg(volume.bytesAvailable());
qDebug() << QString("Bytes free: %L1 Bytes").arg(volume.bytesFree());
qDebug() << QString("Bytes total: %L1 Bytes").arg(volume.bytesTotal()) << endl;

if(volume.isValid() && volume.isReady()
#ifdef Q_OS_LINUX
&& (volume.isRoot() || volume.rootPath().startsWith("/media"))
#endif
)
{
m_infos.push_back({BookmarkInfo::Type::System,
#ifdef Q_OS_LINUX
volume.device(),
#else
volume.displayName(),
#endif
volume.rootPath()});
}
}

for(auto& bookmark : Settings::getInstance()->getBookmarkDirPathList())
{
m_infos.push_back({BookmarkInfo::Type::User, bookmark.first, bookmark.second});
}

return 0;
}

QVariant BookmarkInfoModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(orientation);

if(role == Qt::DisplayRole)
{
if(section == 0)
{
return tr("Name");
}
else if(section == 1)
{
return tr("Path");
}
}

return QVariant();
}
#if 0
bool BookmarkInfoModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
{
if (value != headerData(section, orientation, role)) {
Expand All @@ -22,33 +86,65 @@ bool BookmarkInfoModel::setHeaderData(int section, Qt::Orientation orientation,
}
return false;
}


#endif
int BookmarkInfoModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
if(parent.isValid())
{
return 0;
}

// FIXME: Implement me!
return m_infos.count();
}

int BookmarkInfoModel::columnCount(const QModelIndex &parent) const
{
if (parent.isValid())
if(parent.isValid())
{
return 0;
}

// FIXME: Implement me!
return 2;
}

QVariant BookmarkInfoModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
if(!index.isValid() || index.row() < 0 || index.row() >= m_infos.count())
{
return QVariant();
}

const BookmarkInfo& info = m_infos[index.row()];

switch (role)
{
case Qt::DisplayRole:
if(index.column() == 0)
{
return info.getName();
}
else if(index.column() == 1)
{
return info.getPath();
}
break;
case Qt::DecorationRole:
if(index.column() == 0)
{
return m_fileSystemModel->fileIcon(m_fileSystemModel->index(info.getPath()));
}
break;
case TypeRole:
return info.getTypeName();
case NameRole:
return info.getName();
case PathRole:
return info.getPath();
}

// FIXME: Implement me!
return QVariant();
}

#if 0
bool BookmarkInfoModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (data(index, role) != value) {
Expand Down Expand Up @@ -94,5 +190,14 @@ bool BookmarkInfoModel::removeColumns(int column, int count, const QModelIndex &
// FIXME: Implement me!
endRemoveColumns();
}
#endif
QHash<int, QByteArray> BookmarkInfoModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[TypeRole] = "type";
roles[NameRole] = "name";
roles[PathRole] = "path";
return roles;
}

} // namespace Farman
21 changes: 19 additions & 2 deletions bookmarkinfomodel.h
Expand Up @@ -2,6 +2,8 @@
#define BOOKMARKINFOMODEL_H

#include <QAbstractTableModel>
#include <QFileSystemModel>
#include "bookmarkinfo.h"

namespace Farman
{
Expand All @@ -11,23 +13,31 @@ class BookmarkInfoModel : public QAbstractTableModel
Q_OBJECT

public:
enum Roles
{
TypeRole = Qt::UserRole + 1,
NameRole,
PathRole,
};

explicit BookmarkInfoModel(QObject *parent = nullptr);

// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

#if 0
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
#endif

// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

#if 0
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;

Qt::ItemFlags flags(const QModelIndex& index) const override;

// Add data:
Expand All @@ -37,8 +47,15 @@ class BookmarkInfoModel : public QAbstractTableModel
// Remove data:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override;
#endif
protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;

private:
int initialize();

QList<BookmarkInfo> m_infos;
QFileSystemModel* m_fileSystemModel;
};

} // namespace Farman
Expand Down
4 changes: 2 additions & 2 deletions doublefolderpanel.cpp
Expand Up @@ -14,7 +14,7 @@
#include "settings.h"
#include "fileoperationdialog.h"
#include "fileattributesdialog.h"
#include "selectstoragebookmarkdialog.h"
#include "selectbookmarkdialog.h"
#include "file.h"

namespace Farman
Expand Down Expand Up @@ -341,7 +341,7 @@ void DoubleFolderPanel::onSelectStorageBookmark()
return;
}

SelectStorageBookmarkDialog dialog(parentWidget());
SelectBookmarkDialog dialog(parentWidget());
if(dialog.exec() != QDialog::Accepted)
{
return;
Expand Down
9 changes: 4 additions & 5 deletions farman.pro
Expand Up @@ -30,10 +30,9 @@ SOURCES += main.cpp\
folderviewstyleditemdelegate.cpp \
foldermodel.cpp \
doublefolderpanel.cpp \
selectstoragebookmarkdialog.cpp \
selectbookmarkdialog.cpp \
sortdialog.cpp \
filterdialog.cpp \
storagebookmarkinfomodel.cpp \
workingdialog.cpp \
worker.cpp \
copyworker.cpp \
Expand All @@ -55,6 +54,7 @@ SOURCES += main.cpp\
file.cpp

HEADERS += mainwindow.h \
bookmarkinfo.h \
bookmarkinfomodel.h \
bookmarkmanagerdialog.h \
default_settings.h \
Expand All @@ -63,8 +63,7 @@ HEADERS += mainwindow.h \
foldermodel.h \
folderview.h \
doublefolderpanel.h \
selectstoragebookmarkdialog.h \
storagebookmarkinfomodel.h \
selectbookmarkdialog.h \
types.h \
sortdialog.h \
filterdialog.h \
Expand Down Expand Up @@ -93,7 +92,7 @@ FORMS += mainwindow.ui \
bookmarkmanagerdialog.ui \
folderform.ui \
doublefolderpanel.ui \
selectstoragebookmarkdialog.ui \
selectbookmarkdialog.ui \
sortdialog.ui \
filterdialog.ui \
workingdialog.ui \
Expand Down
35 changes: 35 additions & 0 deletions selectbookmarkdialog.cpp
@@ -0,0 +1,35 @@
#include <QStorageInfo>
#include "selectbookmarkdialog.h"
#include "ui_selectbookmarkdialog.h"

namespace Farman
{

SelectBookmarkDialog::SelectBookmarkDialog(QWidget *parent/* = Q_NULLPTR*/) :
QDialog(parent),
ui(new Ui::SelectBookmarkDialog),
m_bookmarkInfoModel(new BookmarkInfoModel())
{
ui->setupUi(this);

ui->bookmarksTableView->setModel(m_bookmarkInfoModel);
ui->bookmarksTableView->setCurrentIndex(m_bookmarkInfoModel->index(0, 0));

ui->bookmarksTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}

SelectBookmarkDialog::~SelectBookmarkDialog()
{
delete m_bookmarkInfoModel;

delete ui;
}

void SelectBookmarkDialog::accept()
{
m_selectedPath = m_bookmarkInfoModel->data(ui->bookmarksTableView->currentIndex(), BookmarkInfoModel::PathRole).toString();

QDialog::accept();
}

} // namespace Farman

0 comments on commit a3abb85

Please sign in to comment.