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