annotate settingsdialog.cpp @ 0:a9098eba2ee5

Initial commit.
author Jari Korhonen <jtkorhonen@gmail.com>
date Thu, 22 Apr 2010 03:15:35 +0300
parents
children e275d0b5d6ca
rev   line source
jtkorhonen@0 1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl)
jtkorhonen@0 2
jtkorhonen@0 3 #include "settingsdialog.h"
jtkorhonen@0 4
jtkorhonen@0 5 #include <QHBoxLayout>
jtkorhonen@0 6 #include <QVBoxLayout>
jtkorhonen@0 7
jtkorhonen@0 8
jtkorhonen@0 9 SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
jtkorhonen@0 10 {
jtkorhonen@0 11 QPushButton *okButton;
jtkorhonen@0 12 QPushButton *cancelButton;
jtkorhonen@0 13
jtkorhonen@0 14 mainWnd = (MainWindow *) parent;
jtkorhonen@0 15
jtkorhonen@0 16 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
jtkorhonen@0 17 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
jtkorhonen@0 18 userInfoLabel -> setBuddy(userInfoLineEdit);
jtkorhonen@0 19
jtkorhonen@0 20 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
jtkorhonen@0 21 remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath);
jtkorhonen@0 22 remoteRepoLabel -> setBuddy(remoteRepoLineEdit);
jtkorhonen@0 23 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 24
jtkorhonen@0 25 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
jtkorhonen@0 26 workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath);
jtkorhonen@0 27 workFolderLabel -> setBuddy(workFolderLineEdit);
jtkorhonen@0 28 workFolderBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 29
jtkorhonen@0 30 okButton = new QPushButton(tr("Ok"));
jtkorhonen@0 31 cancelButton = new QPushButton(tr("Cancel"));
jtkorhonen@0 32
jtkorhonen@0 33 QHBoxLayout *btnLayout = new QHBoxLayout;
jtkorhonen@0 34 btnLayout -> addWidget(okButton);
jtkorhonen@0 35 btnLayout -> addWidget(cancelButton);
jtkorhonen@0 36 btnLayout -> addStretch();
jtkorhonen@0 37
jtkorhonen@0 38 QHBoxLayout *workFolderLayout = new QHBoxLayout;
jtkorhonen@0 39 workFolderLayout -> addWidget(workFolderLineEdit);
jtkorhonen@0 40 workFolderLayout -> addWidget(workFolderBrowseButton);
jtkorhonen@0 41
jtkorhonen@0 42 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
jtkorhonen@0 43 remoteRepoLayout -> addWidget(remoteRepoLineEdit);
jtkorhonen@0 44 remoteRepoLayout -> addWidget(remoteRepoBrowseButton);
jtkorhonen@0 45
jtkorhonen@0 46 QVBoxLayout *mainLayout = new QVBoxLayout;
jtkorhonen@0 47
jtkorhonen@0 48 mainLayout -> addWidget(userInfoLabel);
jtkorhonen@0 49 mainLayout -> addWidget(userInfoLineEdit);
jtkorhonen@0 50
jtkorhonen@0 51 mainLayout -> addWidget(remoteRepoLabel);
jtkorhonen@0 52 mainLayout -> addLayout(remoteRepoLayout);
jtkorhonen@0 53
jtkorhonen@0 54 mainLayout -> addWidget(workFolderLabel);
jtkorhonen@0 55 mainLayout -> addLayout(workFolderLayout);
jtkorhonen@0 56
jtkorhonen@0 57 mainLayout -> addLayout(btnLayout);
jtkorhonen@0 58
jtkorhonen@0 59 setLayout(mainLayout);
jtkorhonen@0 60
jtkorhonen@0 61 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
jtkorhonen@0 62 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
jtkorhonen@0 63 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
jtkorhonen@0 64 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
jtkorhonen@0 65 }
jtkorhonen@0 66
jtkorhonen@0 67 #define EMPTY_DIR 2
jtkorhonen@0 68
jtkorhonen@0 69 void SettingsDialog::okClicked()
jtkorhonen@0 70 {
jtkorhonen@0 71 mainWnd -> firstStart = false;
jtkorhonen@0 72 mainWnd -> userInfo = userInfoLineEdit->text();
jtkorhonen@0 73 mainWnd -> remoteRepoPath = remoteRepoLineEdit->text();
jtkorhonen@0 74 mainWnd -> workFolderPath = workFolderLineEdit -> text();
jtkorhonen@0 75 mainWnd -> writeSettings();
jtkorhonen@0 76 mainWnd -> enableDisableActions();
jtkorhonen@0 77 mainWnd -> hgStat();
jtkorhonen@0 78 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
jtkorhonen@0 79
jtkorhonen@0 80 QDir dir(mainWnd -> workFolderPath);
jtkorhonen@0 81 if (dir.exists(mainWnd -> workFolderPath))
jtkorhonen@0 82 {
jtkorhonen@0 83 uint cnt = dir.count();
jtkorhonen@0 84 if (cnt == EMPTY_DIR)
jtkorhonen@0 85 {
jtkorhonen@0 86 QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is empty.\nChoose \"File/Clone from remote\"\nto download a remote repository.\nYou can also choose \"File/Init local repository\"\nto initialize repository and add files later."));
jtkorhonen@0 87 }
jtkorhonen@0 88 else
jtkorhonen@0 89 {
jtkorhonen@0 90 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
jtkorhonen@0 91 QDir repoDir(repoPath);
jtkorhonen@0 92 if (!repoDir.exists())
jtkorhonen@0 93 {
jtkorhonen@0 94 QMessageBox::information(this, tr("Todo"), tr("Your chosen workfolder is not empty,\nbut does not yet contain a repository.\nChoose \"File/Init local repository\" \nto initialize repository."));
jtkorhonen@0 95 }
jtkorhonen@0 96 }
jtkorhonen@0 97 }
jtkorhonen@0 98
jtkorhonen@0 99
jtkorhonen@0 100 close();
jtkorhonen@0 101 }
jtkorhonen@0 102
jtkorhonen@0 103
jtkorhonen@0 104 void SettingsDialog::cancelClicked()
jtkorhonen@0 105 {
jtkorhonen@0 106 close();
jtkorhonen@0 107 }
jtkorhonen@0 108
jtkorhonen@0 109
jtkorhonen@0 110 void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit)
jtkorhonen@0 111 {
jtkorhonen@0 112 QString dir;
jtkorhonen@0 113 QString startDir;
jtkorhonen@0 114 QString system;
jtkorhonen@0 115
jtkorhonen@0 116 system = getSystem();
jtkorhonen@0 117 if ((system == "Linux") || (system == "Mac"))
jtkorhonen@0 118 {
jtkorhonen@0 119 startDir = QDir::homePath();
jtkorhonen@0 120 }
jtkorhonen@0 121 else
jtkorhonen@0 122 {
jtkorhonen@0 123 startDir = "c:\\";
jtkorhonen@0 124 }
jtkorhonen@0 125
jtkorhonen@0 126 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
jtkorhonen@0 127 startDir,
jtkorhonen@0 128 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
jtkorhonen@0 129
jtkorhonen@0 130 lineEdit->setText(dir + QDir::separator());
jtkorhonen@0 131 }
jtkorhonen@0 132
jtkorhonen@0 133 void SettingsDialog::browseWorkFolder()
jtkorhonen@0 134 {
jtkorhonen@0 135 browseDirAndSetLineEdit(workFolderLineEdit);
jtkorhonen@0 136 }
jtkorhonen@0 137
jtkorhonen@0 138 void SettingsDialog::browseRemoteRepo()
jtkorhonen@0 139 {
jtkorhonen@0 140 browseDirAndSetLineEdit(remoteRepoLineEdit);
jtkorhonen@0 141 }
jtkorhonen@0 142
jtkorhonen@0 143