-
-
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.
Add a method to use existing game installations from other launchers
This should work for XIVLauncher.Core, XIVQuickLauncher and the official launcher. More testing is needed of course, but the framework is there now.
- Loading branch information
Showing
5 changed files
with
141 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-FileCopyrightText: 2024 Joshua Goins <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include <QtQml> | ||
#include <physis.hpp> | ||
|
||
class ExistingInstallModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
QML_ELEMENT | ||
|
||
public: | ||
enum CustomRoles { | ||
TypeRole = Qt::UserRole, | ||
PathRole, | ||
}; | ||
|
||
explicit ExistingInstallModel(QObject *parent = nullptr); | ||
|
||
QVariant data(const QModelIndex &index, int role) const override; | ||
int rowCount(const QModelIndex &parent) const override; | ||
QHash<int, QByteArray> roleNames() const override; | ||
|
||
private: | ||
void fill(); | ||
|
||
struct ExistingInstall { | ||
ExistingInstallType type; | ||
QString path; | ||
}; | ||
|
||
QList<ExistingInstall> m_existingInstalls; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-FileCopyrightText: 2024 Joshua Goins <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "existinginstallmodel.h" | ||
|
||
#include <KLocalizedString> | ||
|
||
ExistingInstallModel::ExistingInstallModel(QObject *parent) | ||
: QAbstractListModel(parent) | ||
{ | ||
fill(); | ||
} | ||
|
||
QVariant ExistingInstallModel::data(const QModelIndex &index, int role) const | ||
{ | ||
Q_ASSERT(checkIndex(index, QAbstractItemModel::CheckIndexOption::IndexIsValid)); | ||
|
||
const auto &install = m_existingInstalls[index.row()]; | ||
|
||
switch (role) { | ||
case TypeRole: { | ||
switch (install.type) { | ||
case ExistingInstallType::OfficialLauncher: | ||
return i18n("Official Launcher"); | ||
case ExistingInstallType::XIVLauncherCore: | ||
return QStringLiteral("XIVLauncher.Core"); | ||
case ExistingInstallType::XIVOnMac: | ||
return QStringLiteral("XIV on Mac"); | ||
case ExistingInstallType::XIVQuickLauncher: | ||
return QStringLiteral("XIVQuickLauncher"); | ||
default: | ||
return i18n("Unknown"); | ||
} | ||
} | ||
case PathRole: | ||
return install.path; | ||
default: | ||
return {}; | ||
} | ||
} | ||
|
||
int ExistingInstallModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
return parent.isValid() ? 0 : m_existingInstalls.size(); | ||
} | ||
|
||
QHash<int, QByteArray> ExistingInstallModel::roleNames() const | ||
{ | ||
return { | ||
{TypeRole, "type"}, | ||
{PathRole, "path"}, | ||
}; | ||
} | ||
|
||
void ExistingInstallModel::fill() | ||
{ | ||
auto dirs = physis_find_existing_game_dirs(); | ||
for (int i = 0; i < dirs.count; i++) { | ||
// We shouldn't be able to import our own game installs, that's handled elsewhere in the UI | ||
if (dirs.entries[i].install_type != ExistingInstallType::Astra) { | ||
beginInsertRows({}, m_existingInstalls.size(), m_existingInstalls.size()); | ||
m_existingInstalls.push_back(ExistingInstall{.type = dirs.entries[i].install_type, .path = QString::fromUtf8(dirs.entries[i].path)}); | ||
endInsertRows(); | ||
} | ||
} | ||
} | ||
|
||
#include "moc_existinginstallmodel.cpp" |
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