commit f3d5f56692c31ab5201fff8a5ae5e779db84d34b Author: woblight Date: Sat Jun 9 10:42:11 2018 +0200 Initial commit diff --git a/AddonUpdateButton.qml b/AddonUpdateButton.qml new file mode 100644 index 0000000..1c13d86 --- /dev/null +++ b/AddonUpdateButton.qml @@ -0,0 +1,60 @@ +import QtQuick 2.9 +import GitAddonsManager.engine 1.0 +import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.3 + +ToolButton { + id: upBtn + enabled: addon.status == Addon.Ready && (addon.gitStatus != Addon.UpToDate && addon.gitStatus != Addon.Error) + state: addon.gitStatus & ~Addon.MergeStatusMask + icon.color: enabled ? "transparent" : "lightgray" + onClicked: addon.update() + hoverEnabled: true + states: [ + State { + name: Addon.UpToDate + PropertyChanges { + target: upBtn + icon.name: "update-none" + ToolTip.visible: hovered + ToolTip.text: "Up to date" + } + }, + State { + name: Addon.Ahead + PropertyChanges { + target: upBtn + icon.name: "update-low" + ToolTip.visible: hovered + ToolTip.text: "Perform downgrade" + } + }, + State { + name: Addon.Behind + PropertyChanges { + target: upBtn + icon.name: "update-low" + ToolTip.visible: hovered + ToolTip.text: "Perform upgrade" + } + }, + State { + name: Addon.Diverged + PropertyChanges { + target: upBtn + icon.name: "update-high" + ToolTip.visible: hovered + ToolTip.text: "Perform checkout" + } + }, + State { + name: Addon.Error + PropertyChanges { + target: upBtn + icon.name: "update-high" + ToolTip.visible: hovered + ToolTip.text: "Error" + } + } + ] +} diff --git a/AddonsPanel.qml b/AddonsPanel.qml new file mode 100644 index 0000000..b7446d6 --- /dev/null +++ b/AddonsPanel.qml @@ -0,0 +1,117 @@ +import QtQuick 2.9 +import GitAddonsManager.engine 1.0 +import QtQuick.Controls 2.4 +import QtQuick.Layouts 1.3 + +ColumnLayout { + + ToolBar { + Layout.fillWidth: true + RowLayout { + anchors.fill: parent + ToolButton { + hoverEnabled: true + action: addAction + ToolTip.visible: hovered + ToolTip.text: "Download a new addon from a git repository" + } + ToolButton { + hoverEnabled: true + action: updateAllAction + ToolTip.visible: hovered + ToolTip.text: "Upgrade all addons" + } + ToolButton { + hoverEnabled: true + action: openAddonsFolder + ToolTip.visible: hovered + ToolTip.text: "Open addons folder externally" + } + + Item { + Layout.fillWidth: true + } + + ToolButton { + hoverEnabled: true + Layout.alignment: Qt.AlignRight + action: refreshAction + ToolTip.visible: hovered + ToolTip.text: "Refresh addons list and check for updates" + } + } + } + RowLayout { + Layout.fillHeight: true + Layout.fillWidth: true + spacing: 0 + ListView { + ScrollBar.vertical: scrollBar + clip: true + Layout.fillHeight: true + Layout.fillWidth: true + model: Engine.addons + id: listView + + delegate: MouseArea { + property Addon addon: Engine.addons[index] + width: parent.width + implicitHeight: row.height + hoverEnabled: true + id: ma + RowLayout { + spacing: 0 + width: parent.width + id: row + Rectangle { + visible: ma.containsMouse || addonMenu.visible || branchSelector.popup.visible + Layout.fillHeight: true + width: 4 + color: deleteButton.hovered ? "red" : "lightgreen" + } + Label { + id: addonName + text: addon.name + Layout.fillWidth: true + background: ProgressBar { + id: pBar + from: 0 + to: addon.total + value: addon.progress + visible: addon.status == Addon.Status.Busy + indeterminate: to == 0 + } + } + ComboBox { + id: branchSelector + model: addon.branches + onModelChanged: currentIndex = find(addon.currentBranch) + Component.onCompleted: currentIndex = find(addon.currentBranch) + onActivated: addon.currentBranch = currentText + } + AddonUpdateButton { + width: parent.width + } + ToolButton { + icon.name: "overflow-menu" + onClicked: if (!addonMenu.visible) addonMenu.visible = true + checked: addonMenu.visible + Menu { + x: -width + id: addonMenu + visible: false + MenuItem { + enabled: addon.status == Addon.Status.Ready + id: deleteButton + text: qsTr("delete") + icon.name: "delete" + onTriggered: addon.uninstall() + } + } + } + } + } + } + ScrollBar {id: scrollBar; Layout.fillHeight: true; visible: listView.contentHeight > listView.header} + } +} diff --git a/GitAddonsManager.pro b/GitAddonsManager.pro new file mode 100644 index 0000000..f7b9042 --- /dev/null +++ b/GitAddonsManager.pro @@ -0,0 +1,46 @@ +QT += quick widgets concurrent +CONFIG += c++1z + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which as been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + addon.cpp \ + control.cpp + +RESOURCES += qml.qrc + +# Additional import path used to resolve QML modules in Qt Creator's code model +QML_IMPORT_PATH = + +# Additional import path used to resolve QML modules just for Qt Quick Designer +QML_DESIGNER_IMPORT_PATH = + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +HEADERS += \ + addon.h \ + control.h + +LIBS += -lgit2 + +win32 { + DEFINES += "_WIN32_WINNT=0x06010000" +} + +DISTFILES += \ + README.md + +QMAKE_CXXFLAGS += -fconcepts diff --git a/Options.qml b/Options.qml new file mode 100644 index 0000000..7fcb2d7 --- /dev/null +++ b/Options.qml @@ -0,0 +1,43 @@ +import QtQuick 2.9 +import QtQuick.Controls 2.4 +import GitAddonsManager.engine 1.0 +import QtQuick.Layouts 1.3 + + +ColumnLayout { + Frame { + Layout.fillWidth: true + contentItem: RowLayout { + width: parent.width + TextField { + Layout.fillWidth: true + id: path + text: Engine.addonsPath + onAccepted: Engine.addonsPath = text + placeholderText: qsTr("Path to AddOns folder") + hoverEnabled: true + ToolTip.visible: hovered + ToolTip.text: qsTr("Path to the folder containing the addons") + } + Button { + text: qsTr("Browse") + onClicked: fileDialog.visible = true + hoverEnabled: true + ToolTip.visible: hovered + ToolTip.text: qsTr("Choose the folder containing the addons") + } + } + } + CheckBox { + tristate: Engine.minimizeToTray == Engine.MinimizeToTrayAsk + onCheckedChanged: Engine.minimizeToTray = checked ? Engine.MinimizeToTrayYes : Engine.MinimizeToTrayNo + checkState: Engine.minimizeToTray == Engine.MinimizeToTrayAsk ? + Qt.PartiallyChecked : + Engine.minimizeToTray == Engine.MinimizeToTrayYes ? + Qt.Checked : Qt.Unchecked + text: qsTr("Minimize to System Tray") + hoverEnabled: true + ToolTip.visible: hovered + ToolTip.text: qsTr("Minimize to System Tray when the main window is closed.") + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7c0305 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# GitAddonsManager + +Git based World of Warcraft addon manager. + +This application exclusively manage git repositories, addons not containing a git repositories will be ignored. All addons hosted on Gitlab, Github and likes are compatible but must be cloned through git (if you don't know what that means, you will need to redownload your addons through this app). diff --git a/Tray.qml b/Tray.qml new file mode 100644 index 0000000..e8127c6 --- /dev/null +++ b/Tray.qml @@ -0,0 +1,49 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.0 +import Qt.labs.platform 1.0 +import GitAddonsManager.engine 1.0 + + +SystemTrayIcon { + visible: true + iconName: "update-none" + + onActivated: { + window.show() + window.raise() + window.requestActivate() + } + menu: Menu { + visible: false + MenuItem { + text: qsTr("Check for updates") + onTriggered: Engine.scanForAddons() + enabled: Engine.status == Engine.Ready + } + MenuItem { + text: qsTr("Update all") + onTriggered: updateAll() + enabled: availableUpdates > 0 + } + MenuSeparator {} + MenuItem { + text: qsTr("Close") + onTriggered: Qt.quit() + } + } +} diff --git a/addon.cpp b/addon.cpp new file mode 100644 index 0000000..9e09c1d --- /dev/null +++ b/addon.cpp @@ -0,0 +1,545 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "addon.h" +#include +#include +#include +#include "control.h" +#ifdef Q_OS_WIN32 +#include +#include +#endif +#include +#include +#include +#include + +Addon::Addon(QString name, git_repository *repo, QObject *parent) : QObject(parent), + m_name(name), m_repo(repo, &git_repository_free), m_progress(0), m_total(0), m_status(Status::Ready), m_gitStatus(GitStatusFlag::UpToDate), m_pool(new QThreadPool(this)) +{ + connect(this, &Addon::remoteChanged, this, &Addon::fetchRemote); + connect(this, &Addon::currentBranchChanged, this, &Addon::updateGitStatus); + scanBranches(); +} + +QString Addon::name() const +{ + return m_name; +} + +void Addon::setName(QString name) +{ + if (m_name == name) + return; + + m_name = name; + emit nameChanged(m_name); +} + +void Addon::update() +{ + removeSubfolders(); + delegate("Update", [this](){ + git_reference *lbr = nullptr; + git_reference *rbr = nullptr; + git_reference *ubr = nullptr; + int error = git_branch_lookup(&lbr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_LOCAL); + git_annotated_commit *ac; + git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; + opts.checkout_strategy = GIT_CHECKOUT_FORCE; + if (error == GIT_ENOTFOUND) { + git_branch_lookup(&lbr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_REMOTE); + git_annotated_commit_from_ref(&ac, m_repo.get(), lbr); + } else { + git_branch_upstream(&rbr, lbr); + git_annotated_commit_from_ref(&ac, m_repo.get(), rbr); + } + if (!git_branch_is_head(lbr)) + git_repository_set_head(m_repo.get(), git_reference_name(lbr)); + git_reference_set_target(&ubr, lbr, git_annotated_commit_id(ac), nullptr); + git_checkout_head(m_repo.get(), &opts); + + git_annotated_commit_free(ac); + if (rbr) + git_reference_free(rbr); + git_reference_free(lbr); + git_reference_free(ubr); + }, [this](){updateGitStatus();}); + unpackSubfolders(); +} + +void Addon::scanBranches() +{ + delegate("Branch Scan", [this](){ + struct { + QStringList rs; + QStringList bs; + QString cb; + QString cr; + } data; + git_strarray remotes; + int error = git_remote_list(&remotes, m_repo.get()); + for (unsigned int i = 0; i < remotes.count; i++) + data.rs << remotes.strings[i]; + git_strarray_free(&remotes); + + git_branch_iterator *iter = nullptr; + error = git_branch_iterator_new(&iter, m_repo.get(), GIT_BRANCH_ALL); + + git_reference *ref = nullptr; + const char *bname = nullptr; + git_branch_t btype; + while (!(error = git_branch_next(&ref, &btype, iter))) { + git_branch_name(&bname, ref); + data.bs << bname; + if (git_branch_is_head(ref)) { + data.cb = bname; + git_buf buf = GIT_BUF_INIT_CONST(0, nullptr); + (git_reference_is_remote(ref) ? + git_branch_remote_name : + git_branch_upstream_remote + )(&buf, m_repo.get(), git_reference_name(ref)); + data.cr = buf.ptr; + } + git_reference_free(ref); + } + git_branch_iterator_free(iter); + return data; + },[this](auto data){ + setRemote(data.cr); + setCurrentBranch(data.cb); + setRemotes(data.rs); + setBranches(data.bs); + scanSubfolders(); + }); +} + +void Addon::scanSubfolders() +{ + delegate("Subfolders Scan", [this](){ + QStringList sf; + git_object *obj = nullptr; + git_revparse_single(&obj, m_repo.get(), "HEAD^{tree}"); + git_tree *tree = reinterpret_cast(obj); + git_tree_walk(tree, GIT_TREEWALK_PRE, [](const char *root, const git_tree_entry *entry, void *payload) -> int{ + QString path = root; + if (path.isEmpty()) + return 0; + QStringList *sf = static_cast(payload); + QString file = git_tree_entry_name(entry); + if (file.toLower() == path.toLower().chopped(1) + ".toc") { + *sf << path.chopped(1); + return 1; + } + if (path.split("/").size() > 1) + return 1; + return 0; + }, &sf); + git_object_free(obj); + return sf; + },[this](auto subs){setSubfolders(subs);}); +} + +void Addon::setBranches(QStringList branches) +{ + if (m_branches == branches) + return; + + m_branches = branches; + emit branchesChanged(m_branches); +} + +void Addon::setCurrentBranch(QString currentBranch) +{ + if (m_currentBranch == currentBranch) + return; + + m_currentBranch = currentBranch; + emit currentBranchChanged(m_currentBranch); +} + +void Addon::setRemote(QString remote) +{ + if (m_remote == remote) + return; + + m_remote = remote; + emit remoteChanged(m_remote); +} + +void Addon::setRemotes(QStringList remotes) +{ + if (m_remotes == remotes) + return; + + m_remotes = remotes; + emit remotesChanged(m_remotes); +} + +int fetch_progress_cb(const git_transfer_progress *stats, void *payload) { + Addon *a = static_cast(payload); + QMetaObject::invokeMethod(a,"setTotal",Q_ARG(int, stats->total_objects)); + QMetaObject::invokeMethod(a,"setProgress",Q_ARG(int, stats->received_objects)); + return 0; +} +void Addon::fetchRemote(QString remote) +{ + delegate(remote + " Fetch", [this, remote](){ + git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; + fetch_opts.callbacks.transfer_progress = &fetch_progress_cb; + fetch_opts.callbacks.payload = this; + git_remote *r; + git_remote_lookup(&r, m_repo.get(), remote.toLocal8Bit()); + int error = git_remote_fetch(r,nullptr,&fetch_opts,nullptr); + if (error < 0) { + const git_error *e = giterr_last(); + qDebug() <klass, e->message); + } + git_remote_free(r); + }, [this](){updateGitStatus();}); + +} + +void Addon::setProgress(int fetchProgress) +{ + if (m_progress == fetchProgress) + return; + + m_progress = fetchProgress; + emit progressChanged(m_progress); +} + +void Addon::setTotal(int fetchSize) +{ + if (m_total == fetchSize) + return; + + m_total = fetchSize; + emit totalChanged(m_total); +} + +void Addon::setStatus(Addon::Status status) +{ + if (m_status == status) + return; + + m_status = status; + emit statusChanged(m_status); +} + +void Addon::setGitStatus(Addon::GitStatus gitStatus) +{ + if (m_gitStatus == gitStatus) + return; + + m_gitStatus = gitStatus; + emit gitStatusChanged(m_gitStatus); +} + +void Addon::updateGitStatus() +{ + delegate("Git Status Update", [this](){ + git_reference *tr; + git_branch_lookup(&tr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_LOCAL); + if (!tr) { + git_branch_lookup(&tr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_REMOTE); + } + else { + git_reference *rbr; + git_branch_upstream(&rbr, tr); + git_reference_free(tr); + tr = rbr; + } + if (!tr) + return GitStatusFlag::UpToDate; + git_reference *lr; + git_repository_head(&lr, m_repo.get()); + git_annotated_commit *uc; + git_annotated_commit *lc; + git_annotated_commit_from_ref(&uc, m_repo.get(), tr); + git_annotated_commit_from_ref(&lc, m_repo.get(), lr); + size_t ahead; + size_t behind; + git_graph_ahead_behind(&ahead, &behind, m_repo.get(), git_annotated_commit_id(lc), git_annotated_commit_id(uc)); + if (!(ahead || behind)) + return GitStatusFlag::UpToDate; + else if (ahead && !behind) + return GitStatusFlag::Ahead; + else if (!ahead) + return GitStatusFlag::Behind; + else + return GitStatusFlag::Diverged; + + + git_reference_free(tr); + git_reference_free(lr); + git_annotated_commit_free(uc); + git_annotated_commit_free(lc); + /// TODO: check for local changes/merge + /*if (git_repository_head_detached(m_repo.get())) { + setGitStatus(GitStatus::Conflicting); + return; + } + git_reference *tr; + git_branch_lookup(&tr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_LOCAL); + if (!tr) { + git_branch_lookup(&tr, m_repo.get(), m_currentBranch.toLocal8Bit(), GIT_BRANCH_REMOTE); + } + else { + git_reference *rbr; + git_branch_upstream(&rbr, tr); + git_reference_free(tr); + tr = rbr; + } + git_buf buf = GIT_BUF_INIT_CONST(0, nullptr); + git_branch_remote_name(&buf, m_repo.get(), git_reference_name(tr)); + if (buf.ptr != remote()) + setRemote(buf.ptr); + else { + git_annotated_commit *ac; + git_annotated_commit_from_ref(&ac, m_repo.get(), tr); + git_merge_analysis_t an; + git_merge_preference_t pref; + git_merge_analysis(&an, &pref, m_repo.get(),(const git_annotated_commit **)&ac, 1); + if (an & GIT_MERGE_ANALYSIS_UP_TO_DATE) { + if (git_annotated_commit_id(*ac) != git_head) + setGitStatus(GitStatus::Conflicting); + else + setGitStatus(GitStatus::UpToDate); + } + else if (an & GIT_MERGE_ANALYSIS_FASTFORWARD) + setGitStatus(GitStatus::FastForwardable); + else + setGitStatus(GitStatus::Conflicting); + + git_annotated_commit_free(ac); + } + git_reference_free(tr);*/ + + }, [this](auto s){ + setGitStatus(s); + }); +} + +void Addon::uninstall() +{ + removeSubfolders(); + closeRepo(); + delegate("Removing addon folder", [this](){ + removeFolder(Control::instance()->addonsPath() + "/" + m_name); + }, [](){Control::instance()->scanForAddons();}); +} + +void Addon::setSubfolders(QStringList subfolders) +{ + if (m_subfolders == subfolders) + return; + m_subfolders = subfolders; + emit subfoldersChanged(m_subfolders); +} + +void walkFolders(QFileInfo &info, auto f){ + if (info.isDir() && !info.isSymLink()) { + foreach (QFileInfo sub, QDir(info.filePath()).entryInfoList(QDir::AllEntries|QDir::NoDotAndDotDot|QDir::Hidden)) + walkFolders(sub, f); + } + f(info); +} + +void Addon::removeFolder(QString path) { + QFileInfo info(path); + if (info.exists()) { + int i = 0; + walkFolders(info, [ &i](QFileInfo /*info*/){ + i++; + }); + emit totalChanged(i); + i = 0; + walkFolders(info, [this, &i](QFileInfo info){ + if (!info.isSymLink() && info.isDir()) + info.dir().rmdir(info.fileName()); + else + QFile(info.filePath()).remove(); + emit totalChanged(++i); + }); + } +} + +void Addon::removeSubfolders() +{ + delegate("Removing Subfolders", [this](){ + foreach (QString subf, m_subfolders) + removeFolder(Control::instance()->addonsPath() + "/" + subf); + }); +} + +void Addon::unpackSubfolders(){ + delegate("Unpacking Subfolders", [this](){ + QStringList errors; + QDir addonsDir(Control::instance()->addonsPath()); + if (m_subfolders.contains(m_name, Qt::CaseInsensitive)) { + QString oldName = m_name; + setName(m_name + ".repo"); + addonsDir.rename(oldName, m_name); + openRepo(); + } + QDir::setCurrent(addonsDir.canonicalPath()); + QDir dir(m_name); + foreach (QString subfn, m_subfolders) { + QFileInfo addonFolder(subfn); + if (addonFolder.exists()) { + QFileInfo dest(addonFolder.fileName() + ".bak"); + int i = 0; + while (dest.exists()) + dest = QFileInfo(addonFolder.fileName() + ".bak." + QString::number(++i)); + addonsDir.rename(addonFolder.fileName(), dest.fileName()); + if (QFileInfo(subfn).exists()) { + errors << QString("The folder \"%1\" already existed and couldn't be renamed. The addon subfolder has been skipped").arg(subfn, dest.exists()); + continue; + } + errors << QString("The folder \"%1\" already existed and has been renamed to \"%2\"").arg(subfn, dest.fileName()); + } + #ifdef Q_OS_WIN32 + QString link = subfn; + link.replace("/","\\"); + QString target = "./"+m_name+"/"+subfn; + target.replace("/","\\"); + wchar_t link_w[link.size() +1]; + wchar_t target_w[target.size() +1]; + int pos = link.toWCharArray(link_w); + link_w[pos] = '\0'; + pos = target.toWCharArray(target_w); + target_w[pos] = '\0'; + #else + QFile::link("./"+m_name+"/"+subfn, subfn); + #endif + if (!QFileInfo(subfn).exists()) { + dir.rename(subfn, "../"+subfn); + } + QFileInfo info(subfn); + if (!info.exists()) { + errors << "Failed to link or move \""+ info.absoluteFilePath() + "\" to \"" + addonFolder.absoluteFilePath()+"\""; + } + } + return errors; + }, [this](auto errors){ + if (errors.size() > 0) { + setStatus(Status::Error); + //setStatusMessage(errors.join('\n')); + } + }); +} + +QStringList Addon::branches() const +{ + return m_branches; +} + +QString Addon::currentBranch() const +{ + return m_currentBranch; +} + +QString Addon::remote() const +{ + return m_remote; +} + +QStringList Addon::remotes() const +{ + return m_remotes; +} + +int Addon::progress() const +{ + return m_progress; +} + +int Addon::total() const +{ + return m_total; +} + +Addon::Status Addon::status() const +{ + return m_status; +} + +Addon::GitStatus Addon::gitStatus() const +{ + return m_gitStatus; +} + +QStringList Addon::subfolders() const +{ + return m_subfolders; +} + +void Addon::closeRepo() +{ + m_repo.reset(); +} + +void Addon::openRepo() +{ + git_repository *repo = nullptr; + git_repository_open(&repo, (Control::instance()->addonsPath() + "/" + m_name).toLocal8Bit()); + m_repo.reset(repo); +} + +void Addon::delegate(QString taskname, auto work, auto callback) +{ + if (status() != Status::Ready) { + qInfo() << name() << "Enqueueing" << taskname; + m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}}); + return; + } + qInfo() << name() << "Executing " << taskname; + setProgress(0); + setTotal(0); + setStatus(Status::Busy); + using ret_t = typename std::invoke_result::type; + QFuture fut = QtConcurrent::run(m_pool, work); + QFutureWatcher *fw = new QFutureWatcher(); + connect(fw, &QFutureWatcher::finished, [this, callback, fw](){ + setStatus(Status::Ready); + TaskQueue old; + m_tasks.swap(old); + + if constexpr (std::is_same::value) + callback(); + else + callback(fw->result()); + + while(!old.isEmpty()) + m_tasks.enqueue(old.dequeue()); + + if (!m_tasks.isEmpty() && status() != Status::Busy) + m_tasks.dequeue().second(); + }); + connect(fw, &QFutureWatcher::finished, fw, &QFutureWatcher::deleteLater); + fw->setFuture(fut); +} + +void Addon::delegate(QString taskname, auto work) +{ + using ret_t = typename std::invoke_result::type; + if constexpr (std::is_same::value) + delegate(taskname, work, [](){}); + else + delegate(taskname, work, [](ret_t){}); +} diff --git a/addon.h b/addon.h new file mode 100644 index 0000000..dec22bd --- /dev/null +++ b/addon.h @@ -0,0 +1,171 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ADDON_H +#define ADDON_H + +#include +#include +#include +#include +#include + +class git_repository; +using repo_p = std::unique_ptr; + +class QThreadPool; + +class Addon : public QObject +{ + Q_OBJECT + using TaskQueue = QQueue>>; + TaskQueue m_tasks; + + QString m_name; + repo_p m_repo; + + QStringList m_branches; + + QString m_currentBranch; + + QString m_remote; + + QStringList m_remotes; + + int m_progress; + + int m_total; + +public: + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QStringList branches READ branches WRITE setBranches NOTIFY branchesChanged) + Q_PROPERTY(QString currentBranch READ currentBranch WRITE setCurrentBranch NOTIFY currentBranchChanged) + Q_PROPERTY(QString remote READ remote WRITE setRemote NOTIFY remoteChanged) + Q_PROPERTY(QStringList remotes READ remotes WRITE setRemotes NOTIFY remotesChanged) + Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged) + Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged) + Q_PROPERTY(QStringList subfolders READ subfolders WRITE setSubfolders NOTIFY subfoldersChanged) + + enum class Status { + Error = -1, + Ready, + Busy + }; + Q_ENUM(Status) + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + + enum GitStatusFlag { + Error = -1, + UpToDate = 0, + Ahead = 1, + Behind = 2, + Diverged = 3, + FastForward = 4, + Merge = 5, + Conflict = 6, + MergeStatusMask = 0x1100 + }; + Q_ENUM(GitStatusFlag) + Q_DECLARE_FLAGS(GitStatus, GitStatusFlag) + Q_PROPERTY(GitStatus gitStatus READ gitStatus WRITE setGitStatus NOTIFY gitStatusChanged) + Q_FLAGS(GitStatus) + + explicit Addon(QString name, git_repository *repo, QObject *parent = nullptr); + + QString name() const; + + QStringList branches() const; + + QString currentBranch() const; + + QString remote() const; + + QStringList remotes() const; + + int progress() const; + + int total() const; + + Status status() const; + + GitStatus gitStatus() const; + + QStringList subfolders() const; + +private: + + Status m_status; + + GitStatus m_gitStatus; + + QStringList m_subfolders; + + void closeRepo(); + + void openRepo(); + + void delegate(QString taskname, auto work, auto callback); + void delegate(QString taskname, auto work); + + QThreadPool *m_pool; + + void removeFolder(QString path); +signals: + + void nameChanged(QString name); + + void branchesChanged(QStringList branches); + + void currentBranchChanged(QString currentBranch); + + void remoteChanged(QString remote); + + void remotesChanged(QStringList remotes); + + void progressChanged(int progress); + + void totalChanged(int total); + + void statusChanged(Status status); + + void gitStatusChanged(GitStatus gitStatus); + + void subfoldersChanged(QStringList subfolders); + +public slots: + void setName(QString name); + void update(); + void scanBranches(); + void scanSubfolders(); + void setBranches(QStringList branches); + void setCurrentBranch(QString currentBranch); + void setRemote(QString remote); + void setRemotes(QStringList remotes); + void fetchRemote(QString remote); + void setProgress(int progress); + void setTotal(int total); + void setStatus(Status status); + void setGitStatus(GitStatus gitStatus); + void updateGitStatus(); + void uninstall(); + void setSubfolders(QStringList subfolders); + void removeSubfolders(); + void unpackSubfolders(); +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(Addon::GitStatus) + +#endif // ADDON_H diff --git a/control.cpp b/control.cpp new file mode 100644 index 0000000..482402a --- /dev/null +++ b/control.cpp @@ -0,0 +1,288 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "control.h" +#include +#include +#include +#include "addon.h" +#include +#include +#include +#include + +Control *Control::m_instance = nullptr; + +Control::Control(QObject *parent) : QObject(parent), m_progress(0), m_total(0), m_status(Status::Ready), m_statusMessage(""), m_pool(new QThreadPool(this)) +{ + QSettings settings; + setAddonsPath(settings.value("addonsPath").toString()); + setFirstBoot(settings.value("firstBoot",true).toBool()); + setMinimizeToTray((MinimizeToTray)settings.value("minimizeToTray",(int)MinimizeToTrayAsk).toInt()); + connect(this, &Control::addonsPathChanged, this, &Control::scanForAddons); + connect(this, &Control::addonsPathChanged, this, &Control::saveAddonsPath); + delegate("Initializing libgit2...", [](){git_libgit2_init();},[this](){scanForAddons();}); +} + +void Control::delegate(QString taskname, auto work, auto callback) +{ + if (status() != Status::Ready) { + qInfo() << "Enqueueing" << taskname; + m_tasks.enqueue({taskname, [this, taskname, work, callback](){delegate(taskname, work,callback);}}); + return; + } + qInfo() << "Executing " << taskname; + setStatusMessage(taskname); + setProgress(0); + setTotal(0); + setStatus(Status::Busy); + using ret_t = typename std::invoke_result::type; + QFuture fut = QtConcurrent::run(m_pool, work); + QFutureWatcher *fw = new QFutureWatcher(); + connect(fw, &QFutureWatcher::finished, [this, callback, fw](){ + setStatus(Status::Ready); + TaskQueue old; + m_tasks.swap(old); + + if constexpr (std::is_same::value) + callback(); + else + callback(fw->result()); + + while(!old.isEmpty()) + m_tasks.enqueue(old.dequeue()); + + if (!m_tasks.isEmpty() && status() != Status::Busy) + m_tasks.dequeue().second(); + }); + connect(fw, &QFutureWatcher::finished, fw, &QFutureWatcher::deleteLater); + fw->setFuture(fut); +} + +void Control::delegate(QString taskname, auto work) +{ + using ret_t = typename std::invoke_result::type; + if constexpr (std::is_same::value) + delegate(taskname, work, [](){}); + else + delegate(taskname, work, [](ret_t){}); +} + +QList Control::addons() const +{ + return m_addons; +} + +QString Control::addonsPath() const +{ + return m_addonsPath; +} + +Control *Control::instance() +{ + if (!m_instance) + m_instance = new Control(); + return m_instance; +} + +int Control::progress() const +{ + return m_progress; +} + +int Control::total() const +{ + return m_total; +} + +Control::Status Control::status() const +{ + return m_status; +} + +QString Control::statusMessage() const +{ + return m_statusMessage; +} + +bool Control::firstBoot() const +{ + return m_firstBoot; +} + +Control::MinimizeToTray Control::minimizeToTray() const +{ + return m_minimizeToTray; +} + +void Control::setAddons(QList addons) +{ + if (m_addons == addons) + return; + + m_addons = addons; + emit addonsChanged(m_addons); +} + +void Control::setAddonsPath(QString addonsPath) +{ + addonsPath = QUrl::fromLocalFile(addonsPath).adjusted(QUrl::NormalizePathSegments|QUrl::StripTrailingSlash).toLocalFile(); + if (m_addonsPath == addonsPath) + return; + + m_addonsPath = addonsPath; + emit addonsPathChanged(m_addonsPath); +} + +void Control::saveAddonsPath() +{ + QSettings settings; + settings.setValue("addonsPath", m_addonsPath); +} + +void Control::scanForAddons() +{ + using init_t = QPair; + delegate("Scanning addons folder...", [this](){ + QList list; + QDir addonsFolder(m_addonsPath); + foreach (QFileInfo dirInfo, addonsFolder.entryInfoList(QDir::AllDirs)) { + QDir gitdir(dirInfo.canonicalFilePath() + "/.git"); + if (!gitdir.exists()) continue; + git_repository *repo = nullptr; + int error = git_repository_open(&repo, dirInfo.canonicalFilePath().toLocal8Bit()); + if (error) continue; + + //QFileInfo toc(dirInfo.canonicalFilePath() + "/" + dirInfo.fileName() + ".toc"); + //if (toc.exists()) + list << init_t(dirInfo.fileName(), repo); + } + return list; + }, [this](auto list){ + QObjectList ol; + foreach (init_t i, list) + ol << new Addon(i.first, i.second); + setAddons(ol); + }); +} + +int clone_progress_cb(const git_transfer_progress *stats, void *payload) { + Q_UNUSED(payload) + Control::instance()->setTotal(stats->total_objects); + Control::instance()->setProgress(stats->received_objects); + return 0; +} + +void Control::clone(QUrl url) +{ + delegate("Cloning addon...",[this, url]() { + struct { + QString name; + git_repository *repo = nullptr; + QString error; + } data; + data.name = url.fileName().section('.',0,0); + git_clone_options opts = GIT_CLONE_OPTIONS_INIT; + opts.fetch_opts.callbacks.transfer_progress = &clone_progress_cb; + int error = git_clone(&data.repo, url.toString().toLocal8Bit(), (m_addonsPath + "/" + data.name).toLocal8Bit(), &opts); + if (error < 0) { + const git_error *e = giterr_last(); + data.error = QString::asprintf("Error %d/%d: %s", error, e->klass, e->message); + return data; + } + + QDir dir(m_addonsPath); + dir.cd(data.name); + QStringList toc = dir.entryList({"*.toc"}); + if (toc.isEmpty()) { + } else if (toc[0].toLower() != dir.dirName().toLower() + ".toc") { + dir.cdUp(); + QString newName = toc[0].chopped(4); + dir.rename(data.name, newName); + data.name = newName; + } + return data; + },[this](auto ret){ + if (ret.error.isEmpty()) { + auto add = new Addon(ret.name, ret.repo); + m_addons << add; + addonsChanged(m_addons); + add->unpackSubfolders(); + } else { + setStatus(Status::Error); + setStatusMessage(ret.error); + } + }); +} + +void Control::setProgress(int progress) +{ + if (m_progress == progress) + return; + + m_progress = progress; + emit progressChanged(m_progress); +} + +void Control::setTotal(int total) +{ + if (m_total == total) + return; + + m_total = total; + emit totalChanged(m_total); +} + +void Control::setStatus(Control::Status status) +{ + if (m_status == status) + return; + + m_status = status; + emit statusChanged(m_status); +} + +void Control::setStatusMessage(QString statusMessage) +{ + if (m_statusMessage == statusMessage) + return; + + m_statusMessage = statusMessage; + emit statusMessageChanged(m_statusMessage); +} + +void Control::setFirstBoot(bool firstBoot) +{ + if (m_firstBoot == firstBoot) + return; + + m_firstBoot = firstBoot; + emit firstBootChanged(m_firstBoot); + + QSettings s; + s.setValue("firstBoot", false); +} + +void Control::setMinimizeToTray(MinimizeToTray minimizeToTray) +{ + if (m_minimizeToTray == minimizeToTray) + return; + + m_minimizeToTray = minimizeToTray; + emit minimizeToTrayChanged(m_minimizeToTray); + QSettings s; + s.setValue("minimizeToTray",(int)minimizeToTray); +} diff --git a/control.h b/control.h new file mode 100644 index 0000000..e9da5cf --- /dev/null +++ b/control.h @@ -0,0 +1,133 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GITCONTROL_H +#define GITCONTROL_H + +#include +#include +#include +#include + +class QThreadPool; + +class Control : public QObject +{ + Q_OBJECT + + using TaskQueue = QQueue>>; + TaskQueue m_tasks; + + QList m_addons; + + QString m_addonsPath; + +public: + Q_PROPERTY(QList addons READ addons WRITE setAddons NOTIFY addonsChanged) + Q_PROPERTY(QString addonsPath READ addonsPath WRITE setAddonsPath NOTIFY addonsPathChanged) + Q_PROPERTY(int progress READ progress WRITE setProgress NOTIFY progressChanged) + Q_PROPERTY(int total READ total WRITE setTotal NOTIFY totalChanged) + Q_PROPERTY(QString statusMessage READ statusMessage WRITE setStatusMessage NOTIFY statusMessageChanged) + Q_PROPERTY(bool firstBoot READ firstBoot WRITE setFirstBoot NOTIFY firstBootChanged) + + enum class Status { + Error = -1, + Ready, + Busy + }; + Q_ENUM(Status) + Q_PROPERTY(Status status READ status WRITE setStatus NOTIFY statusChanged) + + enum MinimizeToTray { + MinimizeToTrayAsk = -1, + MinimizeToTrayNo = 0, + MinimizeToTrayYes = 1 + }; + Q_ENUM(MinimizeToTray) + Q_PROPERTY(MinimizeToTray minimizeToTray READ minimizeToTray WRITE setMinimizeToTray NOTIFY minimizeToTrayChanged) + + QList addons() const; + + QString addonsPath() const; + + static Control *instance(); + + int progress() const; + + int total() const; + + Status status() const; + + QString statusMessage() const; + + bool firstBoot() const; + + MinimizeToTray minimizeToTray() const; + +private: + static Control *m_instance; + explicit Control(QObject *parent = nullptr); + + int m_progress; + + int m_total; + + Status m_status; + + QString m_statusMessage; + + bool m_firstBoot; + + MinimizeToTray m_minimizeToTray; + + QThreadPool *m_pool; + + void delegate(QString message, auto work, auto callback); + void delegate(QString message, auto work); + +signals: + void addonsChanged(QList addons); + + void addonsPathChanged(QString addonsPath); + + void progressChanged(int progress); + + void totalChanged(int total); + + void statusChanged(Status status); + + void statusMessageChanged(QString statusMessage); + + void firstBootChanged(bool firstBoot); + + void minimizeToTrayChanged(MinimizeToTray minimizeToTray); + +public slots: + void setAddons(QList addons); + void setAddonsPath(QString addonsPath); + void saveAddonsPath(); + void scanForAddons(); + void clone(QUrl url); + void setProgress(int progress); + void setTotal(int total); + void setStatus(Status status); + void setStatusMessage(QString statusMessage); + void setFirstBoot(bool firstBoot); + void setMinimizeToTray(MinimizeToTray minimizeToTray); +}; +Q_DECLARE_METATYPE(Control::MinimizeToTray) + +#endif // GITCONTROL_H diff --git a/github_clone_url.jpg b/github_clone_url.jpg new file mode 100644 index 0000000..85c8dd0 Binary files /dev/null and b/github_clone_url.jpg differ diff --git a/gitlab_clone_url.jpg b/gitlab_clone_url.jpg new file mode 100644 index 0000000..7a9f8f3 Binary files /dev/null and b/gitlab_clone_url.jpg differ diff --git a/icons/breeze/COPYING-ICONS b/icons/breeze/COPYING-ICONS new file mode 100644 index 0000000..63d7365 --- /dev/null +++ b/icons/breeze/COPYING-ICONS @@ -0,0 +1,209 @@ +The Breeze Icon Theme in icons/ + + Copyright (C) 2014 Uri Herrera and others + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . + +Clarification: + + The GNU Lesser General Public License or LGPL is written for + software libraries in the first place. We expressly want the LGPL to + be valid for this artwork library too. + + KDE Breeze theme icons is a special kind of software library, it is an + artwork library, it's elements can be used in a Graphical User Interface, or + GUI. + + Source code, for this library means: + - where they exist, SVG; + - otherwise, if applicable, the multi-layered formats xcf or psd, or + otherwise png. + + The LGPL in some sections obliges you to make the files carry + notices. With images this is in some cases impossible or hardly useful. + + With this library a notice is placed at a prominent place in the directory + containing the elements. You may follow this practice. + + The exception in section 5 of the GNU Lesser General Public License covers + the use of elements of this art library in a GUI. + + https://vdesign.kde.org/ + +----- + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/icons/breeze/index.theme b/icons/breeze/index.theme new file mode 100644 index 0000000..b8ce054 --- /dev/null +++ b/icons/breeze/index.theme @@ -0,0 +1,90 @@ +[Icon Theme] +Name=Breeze +Name[ar]=نسيم +Name[ast]=Breeze +Name[ca]=Brisa +Name[ca@valencia]=Brisa +Name[cs]=Breeze +Name[da]=Breeze +Name[de]=Breeze +Name[el]=Breeze +Name[en_GB]=Breeze +Name[es]=Brisa +Name[et]=Breeze +Name[eu]=Breeze +Name[fi]=Breeze +Name[fr]=Brise +Name[gd]=Oiteag +Name[gl]=Breeze +Name[ia]=Breeze +Name[id]=Breeze +Name[it]=Brezza +Name[ko]=Breeze +Name[nl]=Breeze +Name[nn]=Breeze +Name[pl]=Bryza +Name[pt]=Brisa +Name[pt_BR]=Breeze +Name[ru]=Breeze +Name[sk]=Breeze +Name[sl]=Sapica +Name[sr]=Поветарац +Name[sr@ijekavian]=Поветарац +Name[sr@ijekavianlatin]=Povetarac +Name[sr@latin]=Povetarac +Name[sv]=Breeze +Name[uk]=Breeze +Name[x-test]=xxBreezexx +Name[zh_CN]=微风 +Name[zh_TW]=Breeze + +Comment=Default Plasma 5 Theme +Comment[ar]=سمة «بلازما ٥» الافتراضيّة +Comment[ast]=El tema por defeutu de Plasma 5 +Comment[ca]=Tema del Plasma 5 per defecte +Comment[ca@valencia]=Tema del Plasma 5 per defecte +Comment[cs]=Výchozí motiv Plasma 5 +Comment[da]=Standard Plasma 5-tema +Comment[de]=Standard-Arbeitsflächendesign für Plasma 5 +Comment[el]=Προκαθορισμένο θέμα Plasma 5 +Comment[en_GB]=Default Plasma 5 Theme +Comment[es]=Tema por omisión de Plasma 5 +Comment[et]=Vaikimisi Plasma 5 teema +Comment[eu]=Plasma 5eko gai lehenetsia +Comment[fi]=Plasma 5:n oletusteema +Comment[fr]=Thème par défaut de Plasma 5 +Comment[gd]=Ùrlar Plasma 5 bunaiteach +Comment[gl]=Tema predeterminado de Plasma 5 +Comment[he]=ערכת הנושא הברירת־מחדל של Plama +Comment[ia]=Thema predefinite de Plasma 5 +Comment[id]=Tema Baku Plasma 5 +Comment[it]=Tema predefinito di Plasma 5 +Comment[ko]=기본 Plasma 5 테마 +Comment[nl]=Standaard Plasma 5 thema +Comment[nn]=Standard Plasma 5-tema +Comment[pl]=Domyślny wystrój Plazmy 5 +Comment[pt]=Tema Predefinido do Plasma 5 +Comment[pt_BR]=Tema padrão do Plasma 5 +Comment[ru]=Стандартный набор значков в Plasma 5 +Comment[sk]=Predvolená téma Plasma 5 +Comment[sl]=Privzeta tema za Plasmo 5 +Comment[sr]=Подразумевана тема Плазме 5 +Comment[sr@ijekavian]=Подразумевана тема Плазме 5 +Comment[sr@ijekavianlatin]=Podrazumevana tema Plasme 5 +Comment[sr@latin]=Podrazumevana tema Plasme 5 +Comment[sv]=Plasma 5 standardtema +Comment[tr]=Varsayılan Plasma 5 Teması +Comment[uk]=Типова тема Плазми 5 +Comment[x-test]=xxDefault Plasma 5 Themexx +Comment[zh_CN]=默认 Plasma 5 主题 +Comment[zh_TW]=預設的 Plasma 5 主題 + +DisplayDepth=32 + +FollowsColorScheme=true + +Directories=svg + +[svg] +Type=Fixed +Size=48 diff --git a/icons/breeze/svg/delete.svg b/icons/breeze/svg/delete.svg new file mode 100644 index 0000000..0467306 --- /dev/null +++ b/icons/breeze/svg/delete.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/icons/breeze/svg/go-parent-folder.svg b/icons/breeze/svg/go-parent-folder.svg new file mode 100644 index 0000000..c43ac55 --- /dev/null +++ b/icons/breeze/svg/go-parent-folder.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/icons/breeze/svg/help-whatsthis.svg b/icons/breeze/svg/help-whatsthis.svg new file mode 100644 index 0000000..1bc78de --- /dev/null +++ b/icons/breeze/svg/help-whatsthis.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/icons/breeze/svg/list-add.svg b/icons/breeze/svg/list-add.svg new file mode 100644 index 0000000..a3a2dc5 --- /dev/null +++ b/icons/breeze/svg/list-add.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/icons/breeze/svg/overflow-menu.svg b/icons/breeze/svg/overflow-menu.svg new file mode 100644 index 0000000..1db4d2d --- /dev/null +++ b/icons/breeze/svg/overflow-menu.svg @@ -0,0 +1,69 @@ + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/icons/breeze/svg/update-high.svg b/icons/breeze/svg/update-high.svg new file mode 100644 index 0000000..817c491 --- /dev/null +++ b/icons/breeze/svg/update-high.svg @@ -0,0 +1,21 @@ + + + + + + + diff --git a/icons/breeze/svg/update-low.svg b/icons/breeze/svg/update-low.svg new file mode 100644 index 0000000..8da1865 --- /dev/null +++ b/icons/breeze/svg/update-low.svg @@ -0,0 +1,26 @@ + + + + + + + + + diff --git a/icons/breeze/svg/update-medium.svg b/icons/breeze/svg/update-medium.svg new file mode 100644 index 0000000..7213209 --- /dev/null +++ b/icons/breeze/svg/update-medium.svg @@ -0,0 +1,27 @@ + + + + + + + + + diff --git a/icons/breeze/svg/update-none.svg b/icons/breeze/svg/update-none.svg new file mode 100644 index 0000000..f797e3c --- /dev/null +++ b/icons/breeze/svg/update-none.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/icons/breeze/svg/view-refresh.svg b/icons/breeze/svg/view-refresh.svg new file mode 100644 index 0000000..b0ab47a --- /dev/null +++ b/icons/breeze/svg/view-refresh.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..45304b5 --- /dev/null +++ b/main.cpp @@ -0,0 +1,43 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "control.h" +#include "addon.h" +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication app(argc, argv); + app.setApplicationDisplayName("Git Addons Manager"); + QCoreApplication::setOrganizationName("GitAddonsManager"); + QCoreApplication::setApplicationName("Git Addons Manager"); + + QIcon::setThemeName("breeze"); + + QQmlApplicationEngine engine; + qmlRegisterSingletonType("GitAddonsManager.engine",1,0,"Engine",[](QQmlEngine *, QJSEngine *)->QObject*{ + return Control::instance(); + }); + qmlRegisterUncreatableType("GitAddonsManager.engine",1,0,"Addon",""); + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..97468d3 --- /dev/null +++ b/main.qml @@ -0,0 +1,297 @@ +/* Copyright 2018 WobLight + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.9 +import GitAddonsManager.engine 1.0 +import QtQuick.Controls 2.4 +import QtQuick.Dialogs 1.0 +import QtQuick.Layouts 1.3 + +ApplicationWindow { + visible: true + width: 640 + height: 480 + title: qsTr("Git Addon Updater") + id: window + + property int availableUpdates: 0 + Component.onCompleted: { + availableUpdates = Qt.binding(function(){ + var count = 0 + for (var i = 0; i < Engine.addons.length; i++) { + var addon = Engine.addons[i] + if (addon.gitStatus & Addon.Behind) + count = count + 1 + } + return count + }) + } + + function updateAll() { + for (var i = 0; i < Engine.addons.length; i++) { + var addon = Engine.addons[i] + if (addon.gitStatus & Addon.Behind) + addon.update() + } + } + + onAvailableUpdatesChanged: { + if (availableUpdates > 0) { + tray.showMessage("Addons updates available", "You have " + availableUpdates + " addons waiting for update.", 1, 5000) + } else { + tray.showMessage("Addons up to date", "All addons are updated", 1) + } + } + + onClosing: { + if (Engine.minimizeToTray == Engine.MinimizeToTrayAsk) { + close.accepted = false + closeDialog.visible = true + } else if (Engine.minimizeToTray == Engine.MinimizeToTrayNo) + Qt.quit() + else if (Qt.platform.os == "windows") + window.visible = false + } + + Action { + id: refreshAction + icon.name: "view-refresh" + onTriggered: Engine.scanForAddons() + shortcut: StandardKey.Refresh + } + Action { + id: addAction + icon.name: "list-add" + onTriggered: addDialog.visible = true + shortcut: StandardKey.New + } + Action { + id: updateAllAction + icon.name: availableUpdates > 0 ? "update-high" : "update-none" + onTriggered: updateAll() + enabled: availableUpdates > 0 + } + Action { + id: openAddonsFolder + icon.name: "go-parent-folder" + onTriggered: Qt.openUrlExternally((Qt.platform.os == "windows" ? "file:///" : "file://")+Engine.addonsPath) + } + + ColumnLayout{ + anchors.fill: parent + TabBar { + Layout.fillWidth: true + id: bar + TabButton { + text: qsTr("Addons") + } + TabButton { + text: qsTr("Options") + } + TabButton { + text: qsTr("About") + } + } + + StackLayout { + Layout.fillWidth: true + Layout.fillHeight: true + currentIndex: bar.currentIndex + AddonsPanel { + Layout.fillHeight: true + Layout.fillWidth: true + + } + + Options { + width: parent.width + } + + ColumnLayout { + Label { + text: "Author: woblight " + } + + Label { + text: "Source code: GitLab" + onLinkActivated: Qt.openUrlExternally(link) + textFormat: Text.RichText + } + } + } + } + FileDialog { + id: fileDialog + title: qsTr("Choose addons directory") + folder: Engine.addonsPath != "" ? Engine.addonsPath : shortcuts.home + onAccepted: Engine.addonsPath = fileUrl.toString().replace("file://","") + selectFolder: true + visible: Engine.addonsPath == "" + } + Dialog { + parent: ApplicationWindow.overlay + id: cloneHelpDialog + modal: true + visible: cloneHelpBtn.checked + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + title: qsTr("Clone URL Help") + ColumnLayout { + anchors.fill: parent + Label { + text: "Look for \"clone url\" on the repository webpage, it usually ends in .git" + } + Label { text: "Gitlab" } + Image { + source: "qrc:/gitlab_clone_url.jpg" + fillMode: Image.PreserveAspectCrop + Layout.fillHeight: true + Layout.fillWidth: true + } + Label { text: "Github" } + Image { + source: "qrc:/github_clone_url.jpg" + fillMode: Image.PreserveAspectCrop + Layout.fillHeight: true + Layout.fillWidth: true + } + } + } + Dialog { + width: window.width + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + id: addDialog + title: "Clone Repository" + standardButtons: Dialog.Ok | Dialog.Cancel + RowLayout { + anchors.fill: parent + TextField { + Layout.fillWidth: true + id: addField + placeholderText: "Git clone url" + onAccepted: addDialog.accept() + focus: visible + } + ToolButton { + id: cloneHelpBtn + icon.name: "help-whatsthis" + onClicked: cloneHelpDialog.visible = true + } + } + focus: visible + modal: true + onAccepted: { + Engine.clone(addField.text) + addField.clear() + } + onRejected: addField.clear() + } + + Dialog { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + title: Engine.statusMessage + id: cloningDialong + ProgressBar { + anchors.fill: parent + id: cloningBar + to: Engine.total + value: Engine.progress + indeterminate: to == 0 + } + visible: Engine.status == Engine.Busy + modal: true + closePolicy: Popup.NoAutoClose + } + Dialog { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + title: "An error occourred" + id: errorDialong + Label { + text: Engine.statusMessage + } + visible: Engine.status == Engine.Error + modal: true + closePolicy: Popup.NoAutoClose + standardButtons: Dialog.Ok + onClosed: Engine.status = Engine.Ready + } + Tray { + id: tray + } + + Dialog { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + visible: Engine.addonsPath != "" && !Engine.addonsPath.toLowerCase().match("interface/addons$") + title: qsTr("Warning") + Label { + anchors.fill: parent + text: qsTr("The path set for addons does not appear to be valid. Please make sure it is set to the Interface/AddOns folder inside your World of Warcraft folder.") + wrapMode: Text.WordWrap + } + modal: true + } + + Dialog { + id: closeDialog + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + closePolicy: Popup.NoAutoClose + modal: true + title: qsTr("Choose closing behaviour") + Label { + text: qsTr("Your choise will be saved and be changed any time by the Options panel") + } + footer: DialogButtonBox { + Button { + text: "Close Application" + onClicked: { + Engine.minimizeToTray = Engine.MinimizeToTrayNo + Qt.quit() + } + DialogButtonBox.buttonRole: DialogButtonBox.RejectRole + } + Button { + text: "Minimize in System Tray" + onClicked: { + Engine.minimizeToTray = Engine.MinimizeToTrayYes + close() + } + DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole + } + } + } + Dialog { + x: (parent.width - width) / 2 + y: (parent.height - height) / 2 + visible: Engine.firstBoot + onClosed: Engine.firstBoot = false + title: qsTr("Note on GitAddonsManager") + Label { + anchors.fill: parent + text: qsTr("Greetings,
"+ + "This application will manage only addons cloned with git, not regularly downloaded ones. If you don't know what that means, probably none of your current addons will be listed and only addons added through this aplication will be managed.
"+ + "With this application is only possible to clone (download) addons from git repositories (e.g. Gitlab and Github).
Finally, this is an alpha version things might not go as intended.") + textFormat: Text.RichText + wrapMode: Text.WordWrap + } + modal: true + standardButtons: Dialog.Close + } +} diff --git a/qml.qrc b/qml.qrc new file mode 100644 index 0000000..5794c69 --- /dev/null +++ b/qml.qrc @@ -0,0 +1,23 @@ + + + main.qml + Tray.qml + Options.qml + AddonUpdateButton.qml + AddonsPanel.qml + icons/breeze/svg/delete.svg + icons/breeze/svg/list-add.svg + icons/breeze/svg/overflow-menu.svg + icons/breeze/svg/update-high.svg + icons/breeze/svg/update-low.svg + icons/breeze/svg/update-medium.svg + icons/breeze/svg/update-none.svg + icons/breeze/svg/view-refresh.svg + icons/breeze/COPYING-ICONS + icons/breeze/index.theme + icons/breeze/svg/go-parent-folder.svg + icons/breeze/svg/help-whatsthis.svg + github_clone_url.jpg + gitlab_clone_url.jpg + +