annotate settingsdialog.cpp @ 57:f583e44d9d31

* Update copyrights; add debug header
author Chris Cannam
date Tue, 16 Nov 2010 13:57:30 +0000
parents c76782c14371
children 2340b00561d2
rev   line source
Chris@57 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@57 2
Chris@57 3 /*
Chris@57 4 EasyMercurial
Chris@57 5
Chris@57 6 Based on HgExplorer by Jari Korhonen
Chris@57 7 Copyright (c) 2010 Jari Korhonen
Chris@57 8 Copyright (c) 2010 Chris Cannam
Chris@57 9 Copyright (c) 2010 Queen Mary, University of London
Chris@57 10
Chris@57 11 This program is free software; you can redistribute it and/or
Chris@57 12 modify it under the terms of the GNU General Public License as
Chris@57 13 published by the Free Software Foundation; either version 2 of the
Chris@57 14 License, or (at your option) any later version. See the file
Chris@57 15 COPYING included with this distribution for more information.
Chris@57 16 */
jtkorhonen@0 17
jtkorhonen@0 18 #include "settingsdialog.h"
jtkorhonen@0 19
jtkorhonen@0 20 #include <QHBoxLayout>
jtkorhonen@0 21 #include <QVBoxLayout>
Chris@50 22 #include <QDir>
Chris@50 23 #include <QMessageBox>
Chris@50 24 #include <QFileDialog>
jtkorhonen@0 25
jtkorhonen@0 26 SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
jtkorhonen@0 27 {
jtkorhonen@0 28 QPushButton *okButton;
jtkorhonen@0 29 QPushButton *cancelButton;
jtkorhonen@0 30
jtkorhonen@0 31 mainWnd = (MainWindow *) parent;
jtkorhonen@0 32
jtkorhonen@0 33 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
jtkorhonen@0 34 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
jtkorhonen@0 35 userInfoLabel -> setBuddy(userInfoLineEdit);
jtkorhonen@0 36
jtkorhonen@0 37 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
jtkorhonen@30 38 remoteRepoCombo = new QComboBox();
jtkorhonen@30 39 remoteRepoCombo -> insertItem(0, mainWnd->remoteRepoPath);
jtkorhonen@30 40 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
jtkorhonen@30 41 {
jtkorhonen@30 42 remoteRepoCombo -> insertItem(i + 1, mainWnd -> remoteRepoMruList[i]);
jtkorhonen@30 43 }
jtkorhonen@30 44 remoteRepoCombo -> setEditable(true);
jtkorhonen@30 45 remoteRepoLabel -> setBuddy(remoteRepoCombo);
jtkorhonen@0 46 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 47
jtkorhonen@0 48 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
jtkorhonen@30 49 workFolderCombo = new QComboBox();
jtkorhonen@30 50 workFolderCombo -> insertItem(0, mainWnd -> workFolderPath);
jtkorhonen@30 51 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
jtkorhonen@30 52 {
jtkorhonen@30 53 workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]);
jtkorhonen@30 54 }
jtkorhonen@30 55 workFolderCombo -> setEditable(true);
jtkorhonen@30 56 workFolderLabel -> setBuddy(workFolderCombo);
jtkorhonen@0 57 workFolderBrowseButton = new QPushButton(tr("Browse..."));
jtkorhonen@0 58
jtkorhonen@0 59 okButton = new QPushButton(tr("Ok"));
jtkorhonen@0 60 cancelButton = new QPushButton(tr("Cancel"));
jtkorhonen@0 61
jtkorhonen@0 62 QHBoxLayout *btnLayout = new QHBoxLayout;
jtkorhonen@0 63 btnLayout -> addWidget(okButton);
jtkorhonen@0 64 btnLayout -> addWidget(cancelButton);
jtkorhonen@0 65 btnLayout -> addStretch();
jtkorhonen@0 66
jtkorhonen@0 67 QHBoxLayout *workFolderLayout = new QHBoxLayout;
jtkorhonen@30 68 workFolderLayout -> addWidget(workFolderCombo, 3);
jtkorhonen@30 69 workFolderLayout -> addWidget(workFolderBrowseButton, 1);
jtkorhonen@0 70
jtkorhonen@0 71 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
jtkorhonen@30 72 remoteRepoLayout -> addWidget(remoteRepoCombo, 3);
jtkorhonen@30 73 remoteRepoLayout -> addWidget(remoteRepoBrowseButton, 1);
jtkorhonen@0 74
jtkorhonen@0 75 QVBoxLayout *mainLayout = new QVBoxLayout;
jtkorhonen@0 76
jtkorhonen@0 77 mainLayout -> addWidget(userInfoLabel);
jtkorhonen@0 78 mainLayout -> addWidget(userInfoLineEdit);
jtkorhonen@0 79
jtkorhonen@0 80 mainLayout -> addWidget(remoteRepoLabel);
jtkorhonen@0 81 mainLayout -> addLayout(remoteRepoLayout);
jtkorhonen@0 82
jtkorhonen@0 83 mainLayout -> addWidget(workFolderLabel);
jtkorhonen@0 84 mainLayout -> addLayout(workFolderLayout);
jtkorhonen@0 85
jtkorhonen@0 86 mainLayout -> addLayout(btnLayout);
jtkorhonen@0 87
jtkorhonen@0 88 setLayout(mainLayout);
jtkorhonen@0 89
jtkorhonen@0 90 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
jtkorhonen@0 91 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
jtkorhonen@0 92 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
jtkorhonen@0 93 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
jtkorhonen@0 94 }
jtkorhonen@0 95
jtkorhonen@0 96 #define EMPTY_DIR 2
jtkorhonen@0 97
jtkorhonen@0 98 void SettingsDialog::okClicked()
jtkorhonen@0 99 {
jtkorhonen@30 100 QString tmp;
jtkorhonen@30 101
jtkorhonen@0 102 mainWnd -> firstStart = false;
jtkorhonen@0 103 mainWnd -> userInfo = userInfoLineEdit->text();
jtkorhonen@9 104
jtkorhonen@30 105 if (mainWnd -> remoteRepoPath != remoteRepoCombo-> currentText())
jtkorhonen@9 106 {
jtkorhonen@30 107 insertPathToMruList(mainWnd -> remoteRepoPath, mainWnd -> remoteRepoMruList);
jtkorhonen@30 108 mainWnd -> remoteRepoPath = remoteRepoCombo-> currentText();
jtkorhonen@30 109 }
jtkorhonen@30 110
jtkorhonen@30 111 tmp = workFolderCombo -> currentText();
jtkorhonen@30 112 if (!tmp.endsWith(QDir::separator()))
jtkorhonen@30 113 {
jtkorhonen@30 114 tmp += QDir::separator();
jtkorhonen@30 115 }
jtkorhonen@30 116
jtkorhonen@30 117 if (mainWnd -> workFolderPath != tmp)
jtkorhonen@30 118 {
jtkorhonen@30 119 insertPathToMruList(mainWnd -> workFolderPath, mainWnd -> workFolderMruList);
jtkorhonen@30 120 mainWnd -> workFolderPath = tmp;
jtkorhonen@9 121 }
jtkorhonen@9 122
jtkorhonen@0 123 mainWnd -> writeSettings();
jtkorhonen@0 124 mainWnd -> enableDisableActions();
jtkorhonen@0 125 mainWnd -> hgStat();
jtkorhonen@0 126 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
jtkorhonen@0 127
jtkorhonen@0 128 QDir dir(mainWnd -> workFolderPath);
jtkorhonen@0 129 if (dir.exists(mainWnd -> workFolderPath))
jtkorhonen@0 130 {
jtkorhonen@0 131 uint cnt = dir.count();
jtkorhonen@0 132 if (cnt == EMPTY_DIR)
jtkorhonen@0 133 {
jtkorhonen@0 134 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 135 }
jtkorhonen@0 136 else
jtkorhonen@0 137 {
jtkorhonen@0 138 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
jtkorhonen@0 139 QDir repoDir(repoPath);
jtkorhonen@0 140 if (!repoDir.exists())
jtkorhonen@0 141 {
jtkorhonen@0 142 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 143 }
jtkorhonen@0 144 }
jtkorhonen@0 145 }
jtkorhonen@0 146
jtkorhonen@0 147
jtkorhonen@0 148 close();
jtkorhonen@0 149 }
jtkorhonen@0 150
jtkorhonen@0 151
jtkorhonen@0 152 void SettingsDialog::cancelClicked()
jtkorhonen@0 153 {
jtkorhonen@0 154 close();
jtkorhonen@0 155 }
jtkorhonen@0 156
jtkorhonen@0 157
jtkorhonen@30 158 void SettingsDialog::insertPathToMruList(QString path, QString mruList[])
jtkorhonen@30 159 {
jtkorhonen@30 160 bool matchFound = false;
jtkorhonen@30 161
jtkorhonen@30 162 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
jtkorhonen@30 163 {
jtkorhonen@30 164 if (path == mruList[i])
jtkorhonen@30 165 {
jtkorhonen@30 166 matchFound = true;
jtkorhonen@30 167 break;
jtkorhonen@30 168 }
jtkorhonen@30 169 }
jtkorhonen@30 170
jtkorhonen@30 171 if (!matchFound)
jtkorhonen@30 172 {
jtkorhonen@30 173 for(int i = NUM_PATHS_IN_MRU_LIST - 2; i >= 0; i--)
jtkorhonen@30 174 {
jtkorhonen@30 175 if (i == 0)
jtkorhonen@30 176 {
jtkorhonen@30 177 mruList[1] = mruList[0];
jtkorhonen@30 178 mruList[0] = path;
jtkorhonen@30 179 }
jtkorhonen@30 180 else
jtkorhonen@30 181 {
jtkorhonen@30 182 mruList[i + 1] = mruList[i];
jtkorhonen@30 183 }
jtkorhonen@30 184 }
jtkorhonen@30 185 }
jtkorhonen@30 186 }
jtkorhonen@30 187
jtkorhonen@30 188
jtkorhonen@30 189 void SettingsDialog::browseDirAndSetCombo(QComboBox *combo)
jtkorhonen@0 190 {
jtkorhonen@0 191 QString dir;
jtkorhonen@0 192 QString startDir;
jtkorhonen@0 193 QString system;
jtkorhonen@0 194
jtkorhonen@0 195 system = getSystem();
jtkorhonen@0 196 if ((system == "Linux") || (system == "Mac"))
jtkorhonen@0 197 {
jtkorhonen@0 198 startDir = QDir::homePath();
jtkorhonen@0 199 }
jtkorhonen@0 200 else
jtkorhonen@0 201 {
jtkorhonen@0 202 startDir = "c:\\";
jtkorhonen@0 203 }
jtkorhonen@0 204
jtkorhonen@0 205 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
jtkorhonen@0 206 startDir,
jtkorhonen@0 207 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
jtkorhonen@0 208
jtkorhonen@30 209 combo -> setItemText(0, dir + QDir::separator());
jtkorhonen@0 210 }
jtkorhonen@0 211
jtkorhonen@0 212 void SettingsDialog::browseWorkFolder()
jtkorhonen@0 213 {
jtkorhonen@30 214 browseDirAndSetCombo(workFolderCombo);
jtkorhonen@0 215 }
jtkorhonen@0 216
jtkorhonen@0 217 void SettingsDialog::browseRemoteRepo()
jtkorhonen@0 218 {
jtkorhonen@30 219 browseDirAndSetCombo(remoteRepoCombo);
jtkorhonen@0 220 }
jtkorhonen@0 221
jtkorhonen@0 222