jtkorhonen@30: /**************************************************************************** jtkorhonen@30: ** Copyright (C) Jari Korhonen, 2010 (under lgpl) jtkorhonen@30: ****************************************************************************/ 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 ")); 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@30: remoteRepoCombo = new QComboBox(); jtkorhonen@30: remoteRepoCombo -> insertItem(0, mainWnd->remoteRepoPath); jtkorhonen@30: for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++) jtkorhonen@30: { jtkorhonen@30: remoteRepoCombo -> insertItem(i + 1, mainWnd -> remoteRepoMruList[i]); jtkorhonen@30: } 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); jtkorhonen@30: for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++) jtkorhonen@30: { jtkorhonen@30: workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]); jtkorhonen@30: } 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: jtkorhonen@0: mainWnd -> firstStart = false; jtkorhonen@0: mainWnd -> userInfo = userInfoLineEdit->text(); jtkorhonen@9: jtkorhonen@30: if (mainWnd -> remoteRepoPath != remoteRepoCombo-> currentText()) jtkorhonen@9: { jtkorhonen@30: 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: { jtkorhonen@30: 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@0: jtkorhonen@30: void SettingsDialog::insertPathToMruList(QString path, QString mruList[]) jtkorhonen@30: { jtkorhonen@30: bool matchFound = false; jtkorhonen@30: jtkorhonen@30: for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++) jtkorhonen@30: { jtkorhonen@30: if (path == mruList[i]) jtkorhonen@30: { jtkorhonen@30: matchFound = true; jtkorhonen@30: break; jtkorhonen@30: } jtkorhonen@30: } jtkorhonen@30: jtkorhonen@30: if (!matchFound) jtkorhonen@30: { jtkorhonen@30: for(int i = NUM_PATHS_IN_MRU_LIST - 2; i >= 0; i--) jtkorhonen@30: { jtkorhonen@30: if (i == 0) jtkorhonen@30: { jtkorhonen@30: mruList[1] = mruList[0]; jtkorhonen@30: mruList[0] = path; jtkorhonen@30: } jtkorhonen@30: else jtkorhonen@30: { jtkorhonen@30: mruList[i + 1] = mruList[i]; jtkorhonen@30: } jtkorhonen@30: } jtkorhonen@30: } jtkorhonen@30: } jtkorhonen@30: jtkorhonen@30: 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: