diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..20e6a8a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "sources/3rdparty/task"] + path = sources/3rdparty/task + url = git@github.com:arcan1s/qtadds-taskadds-qprocess.git +[submodule "sources/3rdparty/tasks"] + path = sources/3rdparty/tasks + url = https://github.com/mhogomchungu/tasks.git +[submodule "sources/3rdparty/language"] + path = sources/3rdparty/language + url = git@github.com:arcan1s/qtadds-language.git +[submodule "sources/3rdparty/pdebug"] + path = sources/3rdparty/pdebug + url = git@github.com:arcan1s/qtadds-pdebug.git diff --git a/arch/PKGBUILD b/arch/PKGBUILD index 7cdb640..26260f7 100644 --- a/arch/PKGBUILD +++ b/arch/PKGBUILD @@ -12,7 +12,7 @@ url="http://arcanis.name/projects/netctl-gui" license=('GPL3') makedepends=('automoc4' 'cmake' 'kdelibs' 'qt5-base' 'qt5-tools') source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz") -md5sums=('9b56b04258855258ed30549f1039b8f8') +md5sums=('b5c8fbff66bf5b8374dbe1fa72eb787d') prepare() { diff --git a/create_archive.sh b/create_archive.sh index 9660d67..f9aa04e 100755 --- a/create_archive.sh +++ b/create_archive.sh @@ -3,10 +3,12 @@ ARCHIVE="netctl-gui" SRCDIR="sources" FILES="AUTHORS CHANGELOG COPYING README.md" -IGNORELIST="build en.qm ru.qm netctl-gui.qm *.cppcheck" +IGNORELIST="build *.qm *.cppcheck .git*" VERSION=$(grep -m1 PROJECT_VERSION_MAJOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\ $(grep -m1 PROJECT_VERSION_MINOR sources/CMakeLists.txt | awk '{print $3}' | cut -c 1).\ $(grep -m1 PROJECT_VERSION_PATCH sources/CMakeLists.txt | awk '{print $3}' | cut -c 1) +# update submodules +git submodule update --init --recursive # create archive [[ -e ${ARCHIVE}-${VERSION}-src.tar.xz ]] && rm -f "${ARCHIVE}-${VERSION}-src.tar.xz" [[ -d ${ARCHIVE} ]] && rm -rf "${ARCHIVE}" diff --git a/sources/3rdparty/language b/sources/3rdparty/language new file mode 160000 index 0000000..fe15282 --- /dev/null +++ b/sources/3rdparty/language @@ -0,0 +1 @@ +Subproject commit fe15282d970a65737a26685080910c149ae9856e diff --git a/sources/3rdparty/language/config.h b/sources/3rdparty/language/config.h deleted file mode 100644 index d2ddbe3..0000000 --- a/sources/3rdparty/language/config.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef LANGUAGE_CONFIG_H -#define LANGUAGE_CONFIG_H - - -// put your languages here comma separated -// the first language is default language -#define LANGUAGES "en,ru" -// language key in the configuration file -#define LANGUAGE_KEY "LANGUAGE" - - -#endif /* LANGUAGE_CONFIG_H */ diff --git a/sources/3rdparty/language/language.cpp b/sources/3rdparty/language/language.cpp deleted file mode 100644 index c42eb67..0000000 --- a/sources/3rdparty/language/language.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2014 Evgeniy Alekseev * - * * - * 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.0 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. * - ***************************************************************************/ - - -#include "language.h" - -#include -#include - -#include "config.h" - - -Language::Language() -{ -} - - -QString Language::checkLanguage(const QString language) -{ - QStringList availableLanguages = getAvailableLanguages(); - if (availableLanguages.count() == 0) return QString(); - for (int i=0; i optionsDict = parseOptions(options); - if (optionsDict.contains(QString(LANGUAGE_KEY))) - if (getAvailableLanguages().contains(optionsDict[QString(LANGUAGE_KEY)])) - return optionsDict[QString(LANGUAGE_KEY)]; - - QString language; - language = defineLanguageFromFile(configPath); - if (language.isEmpty()) - language = defineLanguageFromLocale(); - language = checkLanguage(language); - - return language; -} - - -QString Language::defineLanguageFromFile(const QString configPath) -{ - QMap settings; - if (configPath.isEmpty()) - return QString(""); - QFile configFile(configPath); - QString fileStr; - if (!configFile.open(QIODevice::ReadOnly)) - return QString(""); - while (true) { - fileStr = QString(configFile.readLine()).trimmed(); - if ((fileStr.isEmpty()) && (!configFile.atEnd())) continue; - if ((fileStr[0] == QChar('#')) && (!configFile.atEnd())) continue; - if ((fileStr[0] == QChar(';')) && (!configFile.atEnd())) continue; - if (fileStr.contains(QChar('='))) - settings[fileStr.split(QChar('='))[0]] = fileStr.split(QChar('='))[1]; - if (configFile.atEnd()) break; - } - configFile.close(); - - if (settings.contains(QString(LANGUAGE_KEY))) - return settings[QString(LANGUAGE_KEY)]; - else - return QString(""); -} - - -QString Language::defineLanguageFromLocale() -{ - return QLocale::system().name(); -} - - -QStringList Language::getAvailableLanguages() -{ - return QString(LANGUAGES).split(QChar(',')); -} - - -QMap Language::parseOptions(const QString options) -{ - QMap optionsDict; - for (int i=0; i -#include -#include -#include -#include - -/* - * - * Examples on how to use the library are at the end of this file. - * - */ - -namespace Task -{ - class Thread : public QThread - { - Q_OBJECT - public: - Thread() - { - connect( this,SIGNAL( finished() ),this,SLOT( deleteLater() ) ) ; - } - protected: - virtual ~Thread() - { - } - private: - virtual void run( void ) - { - } - }; - - template< typename T > - class future - { - public: - future() : m_function( []( T t ){ Q_UNUSED( t ) ; } ) - { - } - void setActions( std::function< void( void ) > start, - std::function< void( void ) > cancel, - std::function< T ( void ) > get ) - { - m_start = std::move( start ) ; - m_cancel = std::move( cancel ) ; - m_get = std::move( get ) ; - } - void then( std::function< void( T ) > function ) - { - m_function = std::move( function ) ; - m_start() ; - } - T get() - { - return m_get() ; - } - T await() - { - QEventLoop p ; - - T q ; - - m_function = [ & ]( T r ){ q = std::move( r ) ; p.exit() ; } ; - - m_start() ; - - p.exec() ; - - return q ; - } - void start() - { - m_start() ; - } - void cancel() - { - m_cancel() ; - } - void run( T r ) - { - m_function( std::move( r ) ) ; - } - private: - std::function< void( T ) > m_function ; - std::function< void( void ) > m_start ; - std::function< void( void ) > m_cancel ; - std::function< T ( void ) > m_get ; - }; - - template< typename T > - class ThreadHelper : public Thread - { - public: - ThreadHelper( std::function< T ( void ) >&& function ) : m_function( std::move( function ) ) - { - } - future& Future( void ) - { - m_future.setActions( [ this ](){ this->start() ; }, - [ this ](){ this->deleteLater() ; }, - [ this ](){ T r = m_function() ; this->deleteLater() ; return r ; } ) ; - return m_future ; - } - private: - ~ThreadHelper() - { - m_future.run( std::move( m_cargo ) ) ; - } - void run( void ) - { - m_cargo = m_function() ; - } - std::function< T ( void ) > m_function ; - future m_future ; - T m_cargo ; - }; - - class future_1 - { - public: - future_1() : m_function( [](){} ) - { - } - void setActions( std::function< void( void ) > start, - std::function< void( void ) > cancel, - std::function< void( void ) > get ) - { - m_start = std::move( start ) ; - m_cancel = std::move( cancel ) ; - m_get = std::move( get ) ; - } - void then( std::function< void( void ) > function ) - { - m_function = std::move( function ) ; - m_start() ; - } - void get() - { - m_get() ; - } - void await() - { - QEventLoop p ; - - m_function = [ & ](){ p.exit() ; } ; - - m_start() ; - - p.exec() ; - } - void start() - { - m_start() ; - } - void run() - { - m_function() ; - } - void cancel() - { - m_cancel() ; - } - private: - std::function< void( void ) > m_function ; - std::function< void( void ) > m_start ; - std::function< void( void ) > m_cancel ; - std::function< void( void ) > m_get ; - }; - - class ThreadHelper_1 : public Thread - { - public: - ThreadHelper_1( std::function< void ( void ) >&& function ) : m_function( std::move( function ) ) - { - } - future_1& Future( void ) - { - m_future.setActions( [ this ](){ this->start() ; }, - [ this ](){ this->deleteLater() ; }, - [ this ](){ m_function() ; this->deleteLater() ; } ) ; - return m_future ; - } - private: - ~ThreadHelper_1() - { - m_future.run() ; - } - void run( void ) - { - m_function() ; - } - std::function< void ( void ) > m_function ; - future_1 m_future ; - }; - - /* - * Below APIs runs two tasks,the first one will run in a different thread and - * the second one will be run on the original thread after the completion of the - * first one. - */ - - template< typename T > - future& run( std::function< T ( void ) > function ) - { - auto t = new ThreadHelper( std::move( function ) ) ; - return t->Future() ; - } - - static inline future_1& run( std::function< void( void ) > function ) - { - auto t = new ThreadHelper_1( std::move( function ) ) ; - return t->Future() ; - } - - static inline void exec( std::function< void( void ) > function ) - { - Task::run( std::move( function ) ).start() ; - } - - /* - * Below APIs implements resumable functions where a function will be "blocked" - * waiting for the function to return without "hanging" the current thread. - * - * recommending reading up on C#'s await keyword to get a sense of what is being - * discussed below. - */ - - static inline void await( Task::future_1& e ) - { - e.await() ; - } - - static inline void await( std::function< void( void ) > function ) - { - Task::run( std::move( function ) ).await() ; - } - - template< typename T > - T await( std::function< T ( void ) > function ) - { - return Task::run( std::move( function ) ).await() ; - } - - template< typename T > - T await( Task::future& e ) - { - return e.await() ; - } - - template< typename T > - T await( std::future&& t ) - { - return Task::await( [ & ](){ return t.get() ; } ) ; - } -} - -#if 0 - -/* - * Examples on how to use the library - */ -/* - * templated version that passes a return value of one function to another function - */ -auto _a = [](){ - /* - * task _a does what task _a does here. - * - * This function body will run on a different thread - */ - return 0 ; -} - -auto _b = []( int r ){ - /* - * - * task _b does what task _b does here. - * - * r is a const reference to a value returned by _a - * - * This function body will run on the original thread - */ -} - -Task::run( _a ).then( _b ) ; - -alternatively, - -Task::future& e = Task::run( _a ) ; - -e.then( _b ) ; - -/* - * Non templated version that does not pass around return value - */ -auto _c = [](){ - /* - * task _a does what task _a does here. - * - * This function body will run on a different thread - */ -} - -auto _d = [](){ - /* - * task _b does what task _b does here. - * - * r is a const reference to a value returned by _a - * - * This function body will run on the original thread - */ -} - -Task::run( _c ).then( _d ) ; - -/* - * if no continuation - */ -Task::exec( _c ) ; - -/* - * Task::await() is used to "block" without "hanging" the calling thread until the function returns. - * - * Its use case is to do sync programming without hanging the calling thread. - * - * example use case for it is to "block" on function in a GUI thread withough blocking the GUI thread - * hanging the application. - */ - -/* - * await example when the called function return no result - */ -Task::await( _c ) ; - -/* - * await example when the called function return a result - */ -int r = Task::await( _a ) ; - -alternatively, - -Task::future& e = Task::run( _a ) ; - -int r = e.await() ; - -alternatively, - -int r = Task::run( _a ).await() ; - -#endif - -#endif //__TASK_H_INCLUDED__ diff --git a/sources/3rdparty/task/taskadds.cpp b/sources/3rdparty/task/taskadds.cpp deleted file mode 100644 index 0116def..0000000 --- a/sources/3rdparty/task/taskadds.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * This file is part of netctl-gui * - * * - * netctl-gui 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. * - * * - * netctl-gui 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 netctl-gui. If not, see http://www.gnu.org/licenses/ * - ***************************************************************************/ - - -#include "taskadds.h" - - -TaskResult runTask(const QString cmd, const bool useSuid) -{ - return Task::await( [ & ]() { - TaskResult r; - if (useSuid) { - RootProcess command; - command.start(cmd); - command.waitForFinished(-1); - r.exitCode = command.exitCode(); - r.output = command.readAllStandardOutput(); - r.error = command.readAllStandardError(); - } else { - QProcess command; - command.start(cmd); - command.waitForFinished(-1); - r.exitCode = command.exitCode(); - r.output = command.readAllStandardOutput(); - r.error = command.readAllStandardError(); - } - - return r; - }); -} diff --git a/sources/3rdparty/task/taskadds.h b/sources/3rdparty/task/taskadds.h deleted file mode 100644 index 609fcba..0000000 --- a/sources/3rdparty/task/taskadds.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * This file is part of netctl-gui * - * * - * netctl-gui 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. * - * * - * netctl-gui 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 netctl-gui. If not, see http://www.gnu.org/licenses/ * - ***************************************************************************/ - - -#ifndef TASKADDS_H -#define TASKADDS_H - -#include -#include - -#include "task.h" - - -class RootProcess : public QProcess -{ -protected: - void setupChildProcess() - { - ::setuid(0); - }; -}; - - -struct TaskResult -{ - int exitCode; - QByteArray error; - QByteArray output; -}; -TaskResult runTask(const QString cmd, const bool useSuid = true); - - -#endif /* TASKADDS_H */ diff --git a/sources/3rdparty/tasks b/sources/3rdparty/tasks new file mode 160000 index 0000000..f78c18d --- /dev/null +++ b/sources/3rdparty/tasks @@ -0,0 +1 @@ +Subproject commit f78c18d38156e8f7dd0d342d9f8779bed8b7f84e