aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-fm/gitWizard.cpp
blob: f6d6f3b3912129b6f84b6a4283cc6bfa21b68063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
//  This is the dialog for cloning a git repository
//===========================================
#include "gitWizard.h"
#include "ui_gitWizard.h"

#include "gitCompat.h"
#include <QDebug>

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)) );
}

GitWizard::~GitWizard(){

}

//Input values;
void GitWizard::setWorkingDir(QString path){
  inDir = path;
}

//============
//     PRIVATE
// ============
QString GitWizard::assembleURL(){

}

void GitWizard::showDownload(QProcess *P){


  P->deleteLater();
}

//================
//   PRIVATE SLOTS
// ================
void GitWizard::pageChanged(int newpage){
   //called when the "next" button is clicked
  if(this->page(newpage)==ui->page_repo){

  }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") );
    //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();
     
  }else{
    //qDebug() << "Unknown page!" << newpage;
  }
}

void GitWizard::finished(int res){
   //called when the "finish" button is clicked:
  // res==0: window closed (rejected state)
  // res==1: "finish" clicked (accepted state)
  //qDebug() << "Got Finished:" << res;
  if(res == QDialog::Accepted){ 
    qDebug() << "Run git clone";
    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);
    if(proc!=0){
      showDownload(proc);
    }
  }
  
  //this->deleteLater();
}
bgstack15