Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@57: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ jtkorhonen@0: jtkorhonen@0: #include "settingsdialog.h" jtkorhonen@0: jtkorhonen@0: #include jtkorhonen@0: #include Chris@50: #include Chris@50: #include Chris@50: #include 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 ")); Chris@64: 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@30: remoteRepoCombo = new QComboBox(); jtkorhonen@30: remoteRepoCombo -> insertItem(0, mainWnd->remoteRepoPath); Chris@63: /*!!! for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++) jtkorhonen@30: { jtkorhonen@30: remoteRepoCombo -> insertItem(i + 1, mainWnd -> remoteRepoMruList[i]); jtkorhonen@30: } Chris@63: */ jtkorhonen@30: remoteRepoCombo -> setEditable(true); jtkorhonen@30: remoteRepoLabel -> setBuddy(remoteRepoCombo); 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@30: workFolderCombo = new QComboBox(); jtkorhonen@30: workFolderCombo -> insertItem(0, mainWnd -> workFolderPath); Chris@63: /*!!! for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++) jtkorhonen@30: { jtkorhonen@30: workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]); jtkorhonen@30: } Chris@63: */ jtkorhonen@30: workFolderCombo -> setEditable(true); jtkorhonen@30: workFolderLabel -> setBuddy(workFolderCombo); 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@30: workFolderLayout -> addWidget(workFolderCombo, 3); jtkorhonen@30: workFolderLayout -> addWidget(workFolderBrowseButton, 1); jtkorhonen@0: jtkorhonen@0: QHBoxLayout *remoteRepoLayout = new QHBoxLayout; jtkorhonen@30: remoteRepoLayout -> addWidget(remoteRepoCombo, 3); jtkorhonen@30: remoteRepoLayout -> addWidget(remoteRepoBrowseButton, 1); 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@30: QString tmp; jtkorhonen@30: Chris@64: //!!! mainWnd -> firstStart = false; Chris@64: //!!! mainWnd -> userInfo = userInfoLineEdit->text(); jtkorhonen@9: jtkorhonen@30: if (mainWnd -> remoteRepoPath != remoteRepoCombo-> currentText()) jtkorhonen@9: { Chris@63: //!!! insertPathToMruList(mainWnd -> remoteRepoPath, mainWnd -> remoteRepoMruList); jtkorhonen@30: mainWnd -> remoteRepoPath = remoteRepoCombo-> currentText(); jtkorhonen@30: } jtkorhonen@30: jtkorhonen@30: tmp = workFolderCombo -> currentText(); jtkorhonen@30: if (!tmp.endsWith(QDir::separator())) jtkorhonen@30: { jtkorhonen@30: tmp += QDir::separator(); jtkorhonen@30: } jtkorhonen@30: jtkorhonen@30: if (mainWnd -> workFolderPath != tmp) jtkorhonen@30: { Chris@63: //!!! insertPathToMruList(mainWnd -> workFolderPath, mainWnd -> workFolderMruList); jtkorhonen@30: mainWnd -> workFolderPath = tmp; jtkorhonen@9: } jtkorhonen@9: 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@30: void SettingsDialog::browseDirAndSetCombo(QComboBox *combo) 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@30: combo -> setItemText(0, dir + QDir::separator()); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void SettingsDialog::browseWorkFolder() jtkorhonen@0: { jtkorhonen@30: browseDirAndSetCombo(workFolderCombo); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void SettingsDialog::browseRemoteRepo() jtkorhonen@0: { jtkorhonen@30: browseDirAndSetCombo(remoteRepoCombo); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: