jtkorhonen@0: //** Copyright (C) Jari Korhonen, 2010 (under lgpl) jtkorhonen@0: jtkorhonen@0: #include "settingsdialog.h" jtkorhonen@0: jtkorhonen@0: #include jtkorhonen@0: #include jtkorhonen@0: jtkorhonen@0: jtkorhonen@0: SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent) jtkorhonen@0: { jtkorhonen@0: QPushButton *okButton; jtkorhonen@0: QPushButton *cancelButton; jtkorhonen@0: jtkorhonen@0: mainWnd = (MainWindow *) parent; jtkorhonen@0: jtkorhonen@0: userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith ")); jtkorhonen@0: userInfoLineEdit = new QLineEdit(mainWnd->userInfo); jtkorhonen@0: userInfoLabel -> setBuddy(userInfoLineEdit); jtkorhonen@0: jtkorhonen@0: remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\")); jtkorhonen@0: remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath); jtkorhonen@0: remoteRepoLabel -> setBuddy(remoteRepoLineEdit); jtkorhonen@0: remoteRepoBrowseButton = new QPushButton(tr("Browse...")); jtkorhonen@0: jtkorhonen@0: workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\")); jtkorhonen@0: workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath); jtkorhonen@0: workFolderLabel -> setBuddy(workFolderLineEdit); jtkorhonen@0: workFolderBrowseButton = new QPushButton(tr("Browse...")); jtkorhonen@0: jtkorhonen@0: okButton = new QPushButton(tr("Ok")); jtkorhonen@0: cancelButton = new QPushButton(tr("Cancel")); jtkorhonen@0: jtkorhonen@0: QHBoxLayout *btnLayout = new QHBoxLayout; jtkorhonen@0: btnLayout -> addWidget(okButton); jtkorhonen@0: btnLayout -> addWidget(cancelButton); jtkorhonen@0: btnLayout -> addStretch(); jtkorhonen@0: jtkorhonen@0: QHBoxLayout *workFolderLayout = new QHBoxLayout; jtkorhonen@0: workFolderLayout -> addWidget(workFolderLineEdit); jtkorhonen@0: workFolderLayout -> addWidget(workFolderBrowseButton); jtkorhonen@0: jtkorhonen@0: QHBoxLayout *remoteRepoLayout = new QHBoxLayout; jtkorhonen@0: remoteRepoLayout -> addWidget(remoteRepoLineEdit); jtkorhonen@0: remoteRepoLayout -> addWidget(remoteRepoBrowseButton); jtkorhonen@0: jtkorhonen@0: QVBoxLayout *mainLayout = new QVBoxLayout; jtkorhonen@0: jtkorhonen@0: mainLayout -> addWidget(userInfoLabel); jtkorhonen@0: mainLayout -> addWidget(userInfoLineEdit); jtkorhonen@0: jtkorhonen@0: mainLayout -> addWidget(remoteRepoLabel); jtkorhonen@0: mainLayout -> addLayout(remoteRepoLayout); jtkorhonen@0: jtkorhonen@0: mainLayout -> addWidget(workFolderLabel); jtkorhonen@0: mainLayout -> addLayout(workFolderLayout); jtkorhonen@0: jtkorhonen@0: mainLayout -> addLayout(btnLayout); jtkorhonen@0: jtkorhonen@0: setLayout(mainLayout); jtkorhonen@0: jtkorhonen@0: connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked())); jtkorhonen@0: connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked())); jtkorhonen@0: connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder())); jtkorhonen@0: connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo())); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: #define EMPTY_DIR 2 jtkorhonen@0: jtkorhonen@0: void SettingsDialog::okClicked() jtkorhonen@0: { jtkorhonen@0: mainWnd -> firstStart = false; jtkorhonen@0: mainWnd -> userInfo = userInfoLineEdit->text(); jtkorhonen@0: mainWnd -> remoteRepoPath = remoteRepoLineEdit->text(); jtkorhonen@0: mainWnd -> workFolderPath = workFolderLineEdit -> text(); jtkorhonen@0: mainWnd -> writeSettings(); jtkorhonen@0: mainWnd -> enableDisableActions(); jtkorhonen@0: mainWnd -> hgStat(); jtkorhonen@0: mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath); jtkorhonen@0: jtkorhonen@0: QDir dir(mainWnd -> workFolderPath); jtkorhonen@0: if (dir.exists(mainWnd -> workFolderPath)) jtkorhonen@0: { jtkorhonen@0: uint cnt = dir.count(); jtkorhonen@0: if (cnt == EMPTY_DIR) jtkorhonen@0: { jtkorhonen@0: 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: } jtkorhonen@0: else jtkorhonen@0: { jtkorhonen@0: QString repoPath = mainWnd -> workFolderPath + getHgDirName(); jtkorhonen@0: QDir repoDir(repoPath); jtkorhonen@0: if (!repoDir.exists()) jtkorhonen@0: { jtkorhonen@0: 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: } jtkorhonen@0: } jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: jtkorhonen@0: close(); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: jtkorhonen@0: void SettingsDialog::cancelClicked() jtkorhonen@0: { jtkorhonen@0: close(); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: jtkorhonen@0: void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit) jtkorhonen@0: { jtkorhonen@0: QString dir; jtkorhonen@0: QString startDir; jtkorhonen@0: QString system; jtkorhonen@0: jtkorhonen@0: system = getSystem(); jtkorhonen@0: if ((system == "Linux") || (system == "Mac")) jtkorhonen@0: { jtkorhonen@0: startDir = QDir::homePath(); jtkorhonen@0: } jtkorhonen@0: else jtkorhonen@0: { jtkorhonen@0: startDir = "c:\\"; jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), jtkorhonen@0: startDir, jtkorhonen@0: QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); jtkorhonen@0: jtkorhonen@0: lineEdit->setText(dir + QDir::separator()); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void SettingsDialog::browseWorkFolder() jtkorhonen@0: { jtkorhonen@0: browseDirAndSetLineEdit(workFolderLineEdit); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void SettingsDialog::browseRemoteRepo() jtkorhonen@0: { jtkorhonen@0: browseDirAndSetLineEdit(remoteRepoLineEdit); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: