-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9df7bf1
commit 2af2ad5
Showing
9 changed files
with
114 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,73 @@ | ||
#include "library_path_model.hpp" | ||
|
||
namespace firelight::gui { | ||
LibraryPathModel::LibraryPathModel(db::ILibraryDatabase &libraryDatabase) | ||
: m_libraryDatabase(libraryDatabase) { | ||
// m_settings = std::make_unique<QSettings>(); | ||
m_items = m_libraryDatabase.getAllLibraryContentDirectories(); | ||
} | ||
#include <firelight/library/user_library.hpp> | ||
|
||
int LibraryPathModel::rowCount(const QModelIndex &parent) const { | ||
return m_items.size(); | ||
} | ||
namespace firelight::gui { | ||
LibraryPathModel::LibraryPathModel(library::IUserLibrary &userLibrary) | ||
: m_userLibrary(userLibrary) { | ||
// m_settings = std::make_unique<QSettings>(); | ||
m_items = m_userLibrary.getWatchedDirectories(); | ||
} | ||
|
||
QVariant LibraryPathModel::data(const QModelIndex &index, int role) const { | ||
if (role < Qt::UserRole || index.row() >= m_items.size()) { | ||
return {}; | ||
int LibraryPathModel::rowCount(const QModelIndex &parent) const { | ||
return m_items.size(); | ||
} | ||
|
||
auto item = m_items.at(index.row()); | ||
QVariant LibraryPathModel::data(const QModelIndex &index, int role) const { | ||
if (role < Qt::UserRole || index.row() >= m_items.size()) { | ||
return {}; | ||
} | ||
|
||
switch (role) { | ||
case LocalFilename: { | ||
auto t = QString::fromStdString(item.path); | ||
auto val = QUrl::fromUserInput(t); | ||
return val; | ||
} | ||
case Path: { | ||
return QString::fromStdString(item.path); | ||
} | ||
case NumGameFiles: | ||
return item.numGameFiles; | ||
default: | ||
return QVariant{}; | ||
} | ||
} | ||
auto item = m_items.at(index.row()); | ||
|
||
bool LibraryPathModel::setData(const QModelIndex &index, const QVariant &value, | ||
int role) { | ||
if (role < Qt::UserRole || index.row() >= m_items.size()) { | ||
return false; | ||
switch (role) { | ||
case LocalFilename: { | ||
auto val = QUrl::fromUserInput(item.path); | ||
return val; | ||
} | ||
case Path: { | ||
return item.path; | ||
} | ||
case NumGameFiles: | ||
return item.numContentFiles; | ||
default: | ||
return QVariant{}; | ||
} | ||
} | ||
|
||
auto &item = m_items.at(index.row()); | ||
switch (role) { | ||
case Path: | ||
item.path = QUrl(value.toString()).toLocalFile().toStdString(); | ||
m_libraryDatabase.updateLibraryContentDirectory(item); | ||
bool LibraryPathModel::setData(const QModelIndex &index, const QVariant &value, | ||
int role) { | ||
if (role < Qt::UserRole || index.row() >= m_items.size()) { | ||
return false; | ||
} | ||
|
||
auto &item = m_items.at(index.row()); | ||
switch (role) { | ||
case Path: | ||
item.path = QUrl(value.toString()).toLocalFile(); | ||
m_userLibrary.updateWatchedDirectory(item); | ||
|
||
emit dataChanged(index, index, {Path, LocalFilename}); | ||
return true; | ||
case NumGameFiles: | ||
item.numGameFiles = value.toInt(); | ||
emit dataChanged(index, index, {Path, LocalFilename}); | ||
return true; | ||
case NumGameFiles: | ||
item.numContentFiles = value.toInt(); | ||
|
||
emit dataChanged(index, index, {role}); | ||
return true; | ||
default: | ||
return false; | ||
emit dataChanged(index, index, {role}); | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
QHash<int, QByteArray> LibraryPathModel::roleNames() const { | ||
QHash<int, QByteArray> roles; | ||
roles[Path] = "path"; | ||
roles[LocalFilename] = "local_filename"; | ||
roles[NumGameFiles] = "num_game_files"; | ||
return roles; | ||
} | ||
QHash<int, QByteArray> LibraryPathModel::roleNames() const { | ||
QHash<int, QByteArray> roles; | ||
roles[Path] = "path"; | ||
roles[LocalFilename] = "local_filename"; | ||
roles[NumGameFiles] = "num_game_files"; | ||
return roles; | ||
} | ||
|
||
Qt::ItemFlags LibraryPathModel::flags(const QModelIndex &index) const { | ||
return QAbstractListModel::flags(index) | Qt::ItemIsEditable; | ||
} | ||
Qt::ItemFlags LibraryPathModel::flags(const QModelIndex &index) const { | ||
return QAbstractListModel::flags(index) | Qt::ItemIsEditable; | ||
} | ||
} // namespace firelight::gui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters