comparison settingsdialog.cpp @ 30:45bfb8dc1faf

UpdateToRev has more power. Copyrights updated. Mrulist of repos added.
author Jari Korhonen <jtkorhonen@gmail.com>
date Mon, 14 Jun 2010 21:55:17 +0300
parents e376d572b0c4
children c76782c14371
comparison
equal deleted inserted replaced
29:fad897ed9894 30:45bfb8dc1faf
1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl) 1 /****************************************************************************
2 ** Copyright (C) Jari Korhonen, 2010 (under lgpl)
3 ****************************************************************************/
2 4
3 #include "settingsdialog.h" 5 #include "settingsdialog.h"
4 6
5 #include <QHBoxLayout> 7 #include <QHBoxLayout>
6 #include <QVBoxLayout> 8 #include <QVBoxLayout>
15 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>")); 17 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
16 userInfoLineEdit = new QLineEdit(mainWnd->userInfo); 18 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
17 userInfoLabel -> setBuddy(userInfoLineEdit); 19 userInfoLabel -> setBuddy(userInfoLineEdit);
18 20
19 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\")); 21 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
20 remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath); 22 remoteRepoCombo = new QComboBox();
21 remoteRepoLabel -> setBuddy(remoteRepoLineEdit); 23 remoteRepoCombo -> insertItem(0, mainWnd->remoteRepoPath);
24 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
25 {
26 remoteRepoCombo -> insertItem(i + 1, mainWnd -> remoteRepoMruList[i]);
27 }
28 remoteRepoCombo -> setEditable(true);
29 remoteRepoLabel -> setBuddy(remoteRepoCombo);
22 remoteRepoBrowseButton = new QPushButton(tr("Browse...")); 30 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
23 31
24 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\")); 32 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
25 workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath); 33 workFolderCombo = new QComboBox();
26 workFolderLabel -> setBuddy(workFolderLineEdit); 34 workFolderCombo -> insertItem(0, mainWnd -> workFolderPath);
35 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
36 {
37 workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]);
38 }
39 workFolderCombo -> setEditable(true);
40 workFolderLabel -> setBuddy(workFolderCombo);
27 workFolderBrowseButton = new QPushButton(tr("Browse...")); 41 workFolderBrowseButton = new QPushButton(tr("Browse..."));
28 42
29 okButton = new QPushButton(tr("Ok")); 43 okButton = new QPushButton(tr("Ok"));
30 cancelButton = new QPushButton(tr("Cancel")); 44 cancelButton = new QPushButton(tr("Cancel"));
31 45
33 btnLayout -> addWidget(okButton); 47 btnLayout -> addWidget(okButton);
34 btnLayout -> addWidget(cancelButton); 48 btnLayout -> addWidget(cancelButton);
35 btnLayout -> addStretch(); 49 btnLayout -> addStretch();
36 50
37 QHBoxLayout *workFolderLayout = new QHBoxLayout; 51 QHBoxLayout *workFolderLayout = new QHBoxLayout;
38 workFolderLayout -> addWidget(workFolderLineEdit); 52 workFolderLayout -> addWidget(workFolderCombo, 3);
39 workFolderLayout -> addWidget(workFolderBrowseButton); 53 workFolderLayout -> addWidget(workFolderBrowseButton, 1);
40 54
41 QHBoxLayout *remoteRepoLayout = new QHBoxLayout; 55 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
42 remoteRepoLayout -> addWidget(remoteRepoLineEdit); 56 remoteRepoLayout -> addWidget(remoteRepoCombo, 3);
43 remoteRepoLayout -> addWidget(remoteRepoBrowseButton); 57 remoteRepoLayout -> addWidget(remoteRepoBrowseButton, 1);
44 58
45 QVBoxLayout *mainLayout = new QVBoxLayout; 59 QVBoxLayout *mainLayout = new QVBoxLayout;
46 60
47 mainLayout -> addWidget(userInfoLabel); 61 mainLayout -> addWidget(userInfoLabel);
48 mainLayout -> addWidget(userInfoLineEdit); 62 mainLayout -> addWidget(userInfoLineEdit);
65 79
66 #define EMPTY_DIR 2 80 #define EMPTY_DIR 2
67 81
68 void SettingsDialog::okClicked() 82 void SettingsDialog::okClicked()
69 { 83 {
84 QString tmp;
85
70 mainWnd -> firstStart = false; 86 mainWnd -> firstStart = false;
71 mainWnd -> userInfo = userInfoLineEdit->text(); 87 mainWnd -> userInfo = userInfoLineEdit->text();
72 mainWnd -> remoteRepoPath = remoteRepoLineEdit->text(); 88
73 89 if (mainWnd -> remoteRepoPath != remoteRepoCombo-> currentText())
74 mainWnd -> workFolderPath = workFolderLineEdit -> text(); 90 {
75 if (!mainWnd -> workFolderPath.endsWith(QDir::separator())) 91 insertPathToMruList(mainWnd -> remoteRepoPath, mainWnd -> remoteRepoMruList);
76 { 92 mainWnd -> remoteRepoPath = remoteRepoCombo-> currentText();
77 mainWnd -> workFolderPath += QDir::separator(); 93 }
94
95 tmp = workFolderCombo -> currentText();
96 if (!tmp.endsWith(QDir::separator()))
97 {
98 tmp += QDir::separator();
99 }
100
101 if (mainWnd -> workFolderPath != tmp)
102 {
103 insertPathToMruList(mainWnd -> workFolderPath, mainWnd -> workFolderMruList);
104 mainWnd -> workFolderPath = tmp;
78 } 105 }
79 106
80 mainWnd -> writeSettings(); 107 mainWnd -> writeSettings();
81 mainWnd -> enableDisableActions(); 108 mainWnd -> enableDisableActions();
82 mainWnd -> hgStat(); 109 mainWnd -> hgStat();
110 { 137 {
111 close(); 138 close();
112 } 139 }
113 140
114 141
115 void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit) 142 void SettingsDialog::insertPathToMruList(QString path, QString mruList[])
143 {
144 bool matchFound = false;
145
146 for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
147 {
148 if (path == mruList[i])
149 {
150 matchFound = true;
151 break;
152 }
153 }
154
155 if (!matchFound)
156 {
157 for(int i = NUM_PATHS_IN_MRU_LIST - 2; i >= 0; i--)
158 {
159 if (i == 0)
160 {
161 mruList[1] = mruList[0];
162 mruList[0] = path;
163 }
164 else
165 {
166 mruList[i + 1] = mruList[i];
167 }
168 }
169 }
170 }
171
172
173 void SettingsDialog::browseDirAndSetCombo(QComboBox *combo)
116 { 174 {
117 QString dir; 175 QString dir;
118 QString startDir; 176 QString startDir;
119 QString system; 177 QString system;
120 178
130 188
131 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), 189 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
132 startDir, 190 startDir,
133 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); 191 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
134 192
135 lineEdit->setText(dir + QDir::separator()); 193 combo -> setItemText(0, dir + QDir::separator());
136 } 194 }
137 195
138 void SettingsDialog::browseWorkFolder() 196 void SettingsDialog::browseWorkFolder()
139 { 197 {
140 browseDirAndSetLineEdit(workFolderLineEdit); 198 browseDirAndSetCombo(workFolderCombo);
141 } 199 }
142 200
143 void SettingsDialog::browseRemoteRepo() 201 void SettingsDialog::browseRemoteRepo()
144 { 202 {
145 browseDirAndSetLineEdit(remoteRepoLineEdit); 203 browseDirAndSetCombo(remoteRepoCombo);
146 } 204 }
147 205
148 206