Automatically create theme folders, and add an action to open them

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2023-07-19 16:29:52 +01:00
parent c633c6d083
commit 54d393632d
4 changed files with 74 additions and 27 deletions

View File

@ -1134,16 +1134,30 @@ void MainWindow::undoTrashInstance()
ui->actionUndoTrashInstance->setEnabled(APPLICATION->instances()->trashedSomething());
}
void MainWindow::on_actionViewLauncherRootFolder_triggered()
{
DesktopServices::openDirectory(".");
}
void MainWindow::on_actionViewInstanceFolder_triggered()
{
QString str = APPLICATION->settings()->get("InstanceDir").toString();
DesktopServices::openDirectory(str);
}
void MainWindow::on_actionViewLauncherRootFolder_triggered()
void MainWindow::on_actionViewCentralModsFolder_triggered()
{
const QString dataPath = QDir::currentPath();
DesktopServices::openDirectory(dataPath);
DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
}
void MainWindow::on_actionViewIconThemeFolder_triggered()
{
DesktopServices::openDirectory("iconthemes");
}
void MainWindow::on_actionViewWidgetThemeFolder_triggered()
{
DesktopServices::openDirectory("themes");
}
void MainWindow::refreshInstances()
@ -1151,11 +1165,6 @@ void MainWindow::refreshInstances()
APPLICATION->instances()->loadList();
}
void MainWindow::on_actionViewCentralModsFolder_triggered()
{
DesktopServices::openDirectory(APPLICATION->settings()->get("CentralModsDir").toString(), true);
}
void MainWindow::checkForUpdates()
{
if (BuildConfig.UPDATER_ENABLED) {

View File

@ -111,16 +111,18 @@ private slots:
void on_actionChangeInstIcon_triggered();
void on_actionViewInstanceFolder_triggered();
void on_actionViewLauncherRootFolder_triggered();
void on_actionViewInstanceFolder_triggered();
void on_actionViewCentralModsFolder_triggered();
void on_actionViewIconThemeFolder_triggered();
void on_actionViewWidgetThemeFolder_triggered();
void on_actionViewSelectedInstFolder_triggered();
void refreshInstances();
void on_actionViewCentralModsFolder_triggered();
void checkForUpdates();
void on_actionSettings_triggered();

View File

@ -131,7 +131,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
<height>31</height>
</rect>
</property>
<widget class="QMenu" name="fileMenu">
@ -186,9 +186,13 @@
<property name="toolTipsVisible">
<bool>true</bool>
</property>
<addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewLauncherRootFolder"/>
<addaction name="separator"/>
<addaction name="actionViewInstanceFolder"/>
<addaction name="actionViewCentralModsFolder"/>
<addaction name="separator"/>
<addaction name="actionViewIconThemeFolder"/>
<addaction name="actionViewWidgetThemeFolder"/>
</widget>
<widget class="QMenu" name="accountsMenu">
<property name="title">
@ -465,7 +469,8 @@
</action>
<action name="actionExportInstanceZip">
<property name="icon">
<iconset theme="launcher"/>
<iconset theme="launcher">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Prism Launcher (zip)</string>
@ -473,7 +478,8 @@
</action>
<action name="actionExportInstanceMrPack">
<property name="icon">
<iconset theme="modrinth"/>
<iconset theme="modrinth">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Modrinth (mrpack)</string>
@ -481,15 +487,17 @@
</action>
<action name="actionExportInstanceFlamePack">
<property name="icon">
<iconset theme="flame"/>
<iconset theme="flame">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>CurseForge (zip)</string>
<string>CurseForge (zip)</string>
</property>
</action>
<action name="actionExportInstanceToModList">
<property name="icon">
<iconset theme="new"/>
<iconset theme="new">
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>Mod List</string>
@ -552,7 +560,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;View Instance Folder</string>
<string>View &amp;Instance Folder</string>
</property>
<property name="toolTip">
<string>Open the instance folder in a file browser.</string>
@ -564,7 +572,7 @@
<normaloff>.</normaloff>.</iconset>
</property>
<property name="text">
<string>&amp;View Launcher Root Folder</string>
<string>View Launcher &amp;Root Folder</string>
</property>
<property name="toolTip">
<string>Open the launcher's root folder in a file browser.</string>
@ -719,6 +727,28 @@
<string>Open the %1 wiki</string>
</property>
</action>
<action name="actionViewWidgetThemeFolder">
<property name="icon">
<iconset theme="viewfolder"/>
</property>
<property name="text">
<string>View &amp;Widget Themes Folder</string>
</property>
<property name="toolTip">
<string>View Widget Theme Folder</string>
</property>
</action>
<action name="actionViewIconThemeFolder">
<property name="icon">
<iconset theme="viewfolder"/>
</property>
<property name="text">
<string>View I&amp;con Theme Folder</string>
</property>
<property name="toolTip">
<string>View Icon Theme Folder</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -74,10 +74,13 @@ void ThemeManager::initializeIcons()
// TODO: icon themes and instance icons do not mesh well together. Rearrange and fix discrepancies!
// set icon theme search path!
QString themeFolder = "iconthemes";
QDir themeFolder("iconthemes");
if (!themeFolder.mkpath("."))
themeWarningLog() << "Couldn't create icon theme folder";
themeDebugLog() << "Icon Theme Folder Path: " << themeFolder.absolutePath();
auto searchPaths = QIcon::themeSearchPaths();
searchPaths.append(themeFolder);
searchPaths.append(themeFolder.path());
QIcon::setThemeSearchPaths(searchPaths);
themeDebugLog() << "<> Initializing Icon Themes";
@ -93,7 +96,7 @@ void ThemeManager::initializeIcons()
themeDebugLog() << "Loaded Built-In Icon Theme" << id;
}
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot);
QDirIterator directoryIterator(themeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot);
while (directoryIterator.hasNext()) {
QDir dir(directoryIterator.next());
IconTheme theme(dir.dirName(), dir.path());
@ -117,10 +120,13 @@ void ThemeManager::initializeWidgets()
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in
// dropdown?)
QString themeFolder = QDir("./themes/").absoluteFilePath("");
themeDebugLog() << "Theme Folder Path: " << themeFolder;
QDirIterator directoryIterator(themeFolder, QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
QDir themeFolder("themes");
if (!themeFolder.mkpath("."))
themeWarningLog() << "Couldn't create theme folder";
themeDebugLog() << "Theme Folder Path: " << themeFolder.absolutePath();
QDirIterator directoryIterator(themeFolder.path(), QDir::Dirs | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (directoryIterator.hasNext()) {
QDir dir(directoryIterator.next());
QFileInfo themeJson(dir.absoluteFilePath("theme.json"));