diff options
Diffstat (limited to 'src-qt5/desktop-utils')
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/gitCompat.h | 35 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/gitWizard.cpp | 70 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/gitWizard.h | 8 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/gitWizard.ui | 4 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-fm/lumina-fm.pro | 1 |
5 files changed, 101 insertions, 17 deletions
diff --git a/src-qt5/desktop-utils/lumina-fm/gitCompat.h b/src-qt5/desktop-utils/lumina-fm/gitCompat.h index 44c6d5b1..a8b5bd1f 100644 --- a/src-qt5/desktop-utils/lumina-fm/gitCompat.h +++ b/src-qt5/desktop-utils/lumina-fm/gitCompat.h @@ -4,7 +4,7 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== -// This is the backend classe for interacting with the "git" utility +// This is the backend class for interacting with the "git" utility //=========================================== #ifndef _LUMINA_FM_GIT_COMPAT_H #define _LUMINA_FM_GIT_COMPAT_H @@ -12,9 +12,35 @@ #include <QProcess> #include <QString> #include <QProcessEnvironment> - +#include <QDebug> +#include <QTemporaryFile> #include <LuminaUtils.h> +#include <unistd.h> + +class GitProcess : public QProcess{ + Q_OBJECT +private: + QString log; + QFile tmpfile; +public: + GitProcess(); + ~GitProcess(); + + //Optional Inputs + void setSSHPassword(QString pass); //This is only used for SSH access + +private slots: + void cleanup(); + void printoutput(){ qDebug() << "Proc Output:" << this->readAllStandardOutput(); } + +protected: + virtual void setupChildProcess(){ + //Need to disable the controlling terminal within this process + setsid(); //Make current process new session leader - resulting in no controlling terminal for this session + } +}; + class GIT{ public: //Check if the git utility is installed and available @@ -45,10 +71,9 @@ public: } //Setup a process for running the clone operation (so the calling process can hook up any watchers and start it when ready) - static QProcess* setupClone(QString indir, QString url, QString branch = "", int depth = -1){ + static GitProcess* setupClone(QString indir, QString url, QString branch = "", int depth = -1){ //NOTE: The returned QProcess needs to be cleaned up when finished - QProcess *P = new QProcess(); - P->setProcessEnvironment( QProcessEnvironment::systemEnvironment() ); + GitProcess *P = new GitProcess(); P->setWorkingDirectory(indir); P->setProgram("git"); QStringList args; diff --git a/src-qt5/desktop-utils/lumina-fm/gitWizard.cpp b/src-qt5/desktop-utils/lumina-fm/gitWizard.cpp index f6d6f3b3..8f0e6199 100644 --- a/src-qt5/desktop-utils/lumina-fm/gitWizard.cpp +++ b/src-qt5/desktop-utils/lumina-fm/gitWizard.cpp @@ -11,11 +11,23 @@ #include "gitCompat.h" #include <QDebug> +#include <QThread> GitWizard::GitWizard(QWidget *parent) : QWizard(parent), ui(new Ui::GitWizard){ ui->setupUi(this); //load the designer form connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(pageChanged(int)) ); connect(this, SIGNAL(finished(int)), this, SLOT(finished(int)) ); + connect(ui->line_repo_org, SIGNAL(textChanged(const QString&)), this, SLOT(validateRepo()) ); + connect(ui->line_repo_name, SIGNAL(textChanged(const QString&)), this, SLOT(validateRepo()) ); + connect(ui->line_ssh_pass, SIGNAL(textChanged(const QString&)), this, SLOT(validateType()) ); + connect(ui->line_user, SIGNAL(textChanged(const QString&)), this, SLOT(validateType()) ); + connect(ui->line_pass, SIGNAL(textChanged(const QString&)), this, SLOT(validateType()) ); + connect(ui->radio_type_ssh, SIGNAL(clicked()), this, SLOT(validateType()) ); + connect(ui->radio_type_login, SIGNAL(clicked()), this, SLOT(validateType()) ); + connect(ui->radio_type_anon, SIGNAL(clicked()), this, SLOT(validateType()) ); + connect(ui->check_depth, SIGNAL(clicked()), this, SLOT(validateType()) ); + connect(ui->check_branch, SIGNAL(clicked()), this, SLOT(validateType()) ); + validateRepo(); } GitWizard::~GitWizard(){ @@ -31,12 +43,26 @@ void GitWizard::setWorkingDir(QString path){ // PRIVATE // ============ QString GitWizard::assembleURL(){ + QString repo = ui->line_repo_org->text()+"/"+ui->line_repo_name->text()+".git"; + QString url; + if(ui->radio_type_ssh->isChecked()){ url = "git@github.com:"+repo; } + else if(ui->radio_type_anon->isChecked()){ url = "https://github.com/"+repo; } + else if(ui->radio_type_login->isChecked()){ + url = "https://"+ui->line_user->text()+":"+ui->line_pass->text()+"@github.com/"+repo; + } + return url; } -void GitWizard::showDownload(QProcess *P){ - - +void GitWizard::showDownload(GitProcess *P){ + P->start(QIODevice::ReadOnly); + //P->closeWriteChannel(); + //P->closeReadChannel(GitProcess::StandardOutput); + //P->closeReadChannel(GitProcess::StandardError); + while(P->state()!=QProcess::NotRunning){ + this->thread()->usleep(50000); //50 ms + QApplication::processEvents(); + } P->deleteLater(); } @@ -46,18 +72,18 @@ void GitWizard::showDownload(QProcess *P){ void GitWizard::pageChanged(int newpage){ //called when the "next" button is clicked if(this->page(newpage)==ui->page_repo){ - + validateRepo(); }else if(this->page(newpage)==ui->page_type){ //Need to adjust items on this page based on info on last page ui->radio_type_anon->setEnabled( !ui->check_privaterepo->isChecked() ); - ui->radio_type_ssh->setEnabled( QFile::exists(QDir::homePath()+"/.ssh/id_rsa") ); + ui->radio_type_ssh->setEnabled( QFile::exists(QDir::homePath()+"/.ssh/id_rsa") ); //TODO - Disable for now until SSH passphrases can be used properly //Now set the preferred type of login based on which are available if(ui->radio_type_ssh->isEnabled()){ ui->radio_type_ssh->setChecked(true); } //SSH is preferred if that is available else if(ui->radio_type_anon->isEnabled()){ ui->radio_type_anon->setChecked(true); } //anonymous next since it is a public repo - no creds really needed else{ ui->radio_type_login->setChecked(true); } //Clear any of the UI as needed ui->line_user->clear(); ui->line_pass->clear(); ui->line_ssh_pass->clear(); - + validateType(); }else{ //qDebug() << "Unknown page!" << newpage; } @@ -73,11 +99,39 @@ void GitWizard::finished(int res){ QString url = assembleURL(); QString branch; if(ui->check_branch->isChecked()){ branch = ui->line_branch->text(); } int depth = -1; if(ui->check_depth->isChecked()){ depth = ui->spin_depth->value(); } - QProcess *proc = GIT::setupClone(inDir, url, branch, depth); + GitProcess *proc = GIT::setupClone(inDir, url, branch, depth); if(proc!=0){ + if(ui->radio_type_ssh->isChecked()){ + proc->setSSHPassword(ui->line_ssh_pass->text()); + } showDownload(proc); } } - //this->deleteLater(); + this->deleteLater(); +} + +//Page validation slots +void GitWizard::validateRepo(){ + bool ok = !ui->line_repo_org->text().isEmpty() && !ui->line_repo_name->text().isEmpty(); + this->button(QWizard::NextButton)->setEnabled(ok); +} + +void GitWizard::validateType(){ + bool ok = false; + //Check types first + if(ui->radio_type_login->isChecked()){ ok = !ui->line_user->text().isEmpty() && !ui->line_pass->text().isEmpty(); } + else{ ok = true; } + //Now check optional settings + if(ui->check_branch->isChecked()){ ok = ok && !ui->line_branch->text().isEmpty(); } + if(ui->check_branch->isChecked()){ ok = ok && !ui->line_branch->text().isEmpty(); } + //Now make interface boxes appear/disappear as needed + ui->line_ssh_pass->setVisible(ui->radio_type_ssh->isChecked()); + ui->line_user->setVisible(ui->radio_type_login->isChecked()); + ui->line_pass->setVisible(ui->radio_type_login->isChecked()); + ui->spin_depth->setVisible(ui->check_depth->isChecked()); + ui->line_branch->setVisible(ui->check_branch->isChecked()); + + //Update the button as needed + this->button(QWizard::FinishButton)->setEnabled(ok); } diff --git a/src-qt5/desktop-utils/lumina-fm/gitWizard.h b/src-qt5/desktop-utils/lumina-fm/gitWizard.h index a95ecb2b..e68ac82d 100644 --- a/src-qt5/desktop-utils/lumina-fm/gitWizard.h +++ b/src-qt5/desktop-utils/lumina-fm/gitWizard.h @@ -11,7 +11,8 @@ #include <QWizard> #include <QString> -#include <QProcess> + +#include "gitCompat.h" namespace Ui{ class GitWizard; @@ -31,13 +32,16 @@ private: QString inDir; QString assembleURL(); - void showDownload(QProcess *P); + void showDownload(GitProcess *P); private slots: //Page Change slots void pageChanged(int newpage); //called when the "next" button is clicked void finished(int); //called when the "finish" button is clicked + //Page validation slots + void validateRepo(); //for page_repo + void validateType(); //for page_type }; #endif diff --git a/src-qt5/desktop-utils/lumina-fm/gitWizard.ui b/src-qt5/desktop-utils/lumina-fm/gitWizard.ui index 94aec4e0..86a5ccb1 100644 --- a/src-qt5/desktop-utils/lumina-fm/gitWizard.ui +++ b/src-qt5/desktop-utils/lumina-fm/gitWizard.ui @@ -54,7 +54,7 @@ </widget> </item> <item row="0" column="1"> - <widget class="QLineEdit" name="lineEdit_2"/> + <widget class="QLineEdit" name="line_repo_org"/> </item> <item row="1" column="0"> <widget class="QLabel" name="label_3"> @@ -64,7 +64,7 @@ </widget> </item> <item row="1" column="1"> - <widget class="QLineEdit" name="lineEdit_3"/> + <widget class="QLineEdit" name="line_repo_name"/> </item> <item row="2" column="1"> <widget class="QCheckBox" name="check_privaterepo"> diff --git a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro index 56314ee6..91e2952c 100644 --- a/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro +++ b/src-qt5/desktop-utils/lumina-fm/lumina-fm.pro @@ -16,6 +16,7 @@ SOURCES += main.cpp \ widgets/MultimediaWidget.cpp \ widgets/SlideshowWidget.cpp \ widgets/DirWidget.cpp \ + gitCompat.cpp \ gitWizard.cpp HEADERS += MainUI.h \ |