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);
|
Chris@63
|
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 }
|
Chris@63
|
44 */
|
jtkorhonen@30
|
45 remoteRepoCombo -> setEditable(true);
|
jtkorhonen@30
|
46 remoteRepoLabel -> setBuddy(remoteRepoCombo);
|
jtkorhonen@0
|
47 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
|
jtkorhonen@0
|
48
|
jtkorhonen@0
|
49 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
|
jtkorhonen@30
|
50 workFolderCombo = new QComboBox();
|
jtkorhonen@30
|
51 workFolderCombo -> insertItem(0, mainWnd -> workFolderPath);
|
Chris@63
|
52 /*!!! for(int i = 0; i < NUM_PATHS_IN_MRU_LIST; i++)
|
jtkorhonen@30
|
53 {
|
jtkorhonen@30
|
54 workFolderCombo -> insertItem(i + 1, mainWnd -> workFolderMruList[i]);
|
jtkorhonen@30
|
55 }
|
Chris@63
|
56 */
|
jtkorhonen@30
|
57 workFolderCombo -> setEditable(true);
|
jtkorhonen@30
|
58 workFolderLabel -> setBuddy(workFolderCombo);
|
jtkorhonen@0
|
59 workFolderBrowseButton = new QPushButton(tr("Browse..."));
|
jtkorhonen@0
|
60
|
jtkorhonen@0
|
61 okButton = new QPushButton(tr("Ok"));
|
jtkorhonen@0
|
62 cancelButton = new QPushButton(tr("Cancel"));
|
jtkorhonen@0
|
63
|
jtkorhonen@0
|
64 QHBoxLayout *btnLayout = new QHBoxLayout;
|
jtkorhonen@0
|
65 btnLayout -> addWidget(okButton);
|
jtkorhonen@0
|
66 btnLayout -> addWidget(cancelButton);
|
jtkorhonen@0
|
67 btnLayout -> addStretch();
|
jtkorhonen@0
|
68
|
jtkorhonen@0
|
69 QHBoxLayout *workFolderLayout = new QHBoxLayout;
|
jtkorhonen@30
|
70 workFolderLayout -> addWidget(workFolderCombo, 3);
|
jtkorhonen@30
|
71 workFolderLayout -> addWidget(workFolderBrowseButton, 1);
|
jtkorhonen@0
|
72
|
jtkorhonen@0
|
73 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
|
jtkorhonen@30
|
74 remoteRepoLayout -> addWidget(remoteRepoCombo, 3);
|
jtkorhonen@30
|
75 remoteRepoLayout -> addWidget(remoteRepoBrowseButton, 1);
|
jtkorhonen@0
|
76
|
jtkorhonen@0
|
77 QVBoxLayout *mainLayout = new QVBoxLayout;
|
jtkorhonen@0
|
78
|
jtkorhonen@0
|
79 mainLayout -> addWidget(userInfoLabel);
|
jtkorhonen@0
|
80 mainLayout -> addWidget(userInfoLineEdit);
|
jtkorhonen@0
|
81
|
jtkorhonen@0
|
82 mainLayout -> addWidget(remoteRepoLabel);
|
jtkorhonen@0
|
83 mainLayout -> addLayout(remoteRepoLayout);
|
jtkorhonen@0
|
84
|
jtkorhonen@0
|
85 mainLayout -> addWidget(workFolderLabel);
|
jtkorhonen@0
|
86 mainLayout -> addLayout(workFolderLayout);
|
jtkorhonen@0
|
87
|
jtkorhonen@0
|
88 mainLayout -> addLayout(btnLayout);
|
jtkorhonen@0
|
89
|
jtkorhonen@0
|
90 setLayout(mainLayout);
|
jtkorhonen@0
|
91
|
jtkorhonen@0
|
92 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
|
jtkorhonen@0
|
93 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
jtkorhonen@0
|
94 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
|
jtkorhonen@0
|
95 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
|
jtkorhonen@0
|
96 }
|
jtkorhonen@0
|
97
|
jtkorhonen@0
|
98 #define EMPTY_DIR 2
|
jtkorhonen@0
|
99
|
jtkorhonen@0
|
100 void SettingsDialog::okClicked()
|
jtkorhonen@0
|
101 {
|
jtkorhonen@30
|
102 QString tmp;
|
jtkorhonen@30
|
103
|
jtkorhonen@0
|
104 mainWnd -> firstStart = false;
|
jtkorhonen@0
|
105 mainWnd -> userInfo = userInfoLineEdit->text();
|
jtkorhonen@9
|
106
|
jtkorhonen@30
|
107 if (mainWnd -> remoteRepoPath != remoteRepoCombo-> currentText())
|
jtkorhonen@9
|
108 {
|
Chris@63
|
109 //!!! insertPathToMruList(mainWnd -> remoteRepoPath, mainWnd -> remoteRepoMruList);
|
jtkorhonen@30
|
110 mainWnd -> remoteRepoPath = remoteRepoCombo-> currentText();
|
jtkorhonen@30
|
111 }
|
jtkorhonen@30
|
112
|
jtkorhonen@30
|
113 tmp = workFolderCombo -> currentText();
|
jtkorhonen@30
|
114 if (!tmp.endsWith(QDir::separator()))
|
jtkorhonen@30
|
115 {
|
jtkorhonen@30
|
116 tmp += QDir::separator();
|
jtkorhonen@30
|
117 }
|
jtkorhonen@30
|
118
|
jtkorhonen@30
|
119 if (mainWnd -> workFolderPath != tmp)
|
jtkorhonen@30
|
120 {
|
Chris@63
|
121 //!!! insertPathToMruList(mainWnd -> workFolderPath, mainWnd -> workFolderMruList);
|
jtkorhonen@30
|
122 mainWnd -> workFolderPath = tmp;
|
jtkorhonen@9
|
123 }
|
jtkorhonen@9
|
124
|
jtkorhonen@0
|
125 mainWnd -> writeSettings();
|
jtkorhonen@0
|
126 mainWnd -> enableDisableActions();
|
jtkorhonen@0
|
127 mainWnd -> hgStat();
|
jtkorhonen@0
|
128 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
|
jtkorhonen@0
|
129
|
jtkorhonen@0
|
130 QDir dir(mainWnd -> workFolderPath);
|
jtkorhonen@0
|
131 if (dir.exists(mainWnd -> workFolderPath))
|
jtkorhonen@0
|
132 {
|
jtkorhonen@0
|
133 uint cnt = dir.count();
|
jtkorhonen@0
|
134 if (cnt == EMPTY_DIR)
|
jtkorhonen@0
|
135 {
|
jtkorhonen@0
|
136 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
|
137 }
|
jtkorhonen@0
|
138 else
|
jtkorhonen@0
|
139 {
|
jtkorhonen@0
|
140 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
|
jtkorhonen@0
|
141 QDir repoDir(repoPath);
|
jtkorhonen@0
|
142 if (!repoDir.exists())
|
jtkorhonen@0
|
143 {
|
jtkorhonen@0
|
144 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
|
145 }
|
jtkorhonen@0
|
146 }
|
jtkorhonen@0
|
147 }
|
jtkorhonen@0
|
148
|
jtkorhonen@0
|
149
|
jtkorhonen@0
|
150 close();
|
jtkorhonen@0
|
151 }
|
jtkorhonen@0
|
152
|
jtkorhonen@0
|
153
|
jtkorhonen@0
|
154 void SettingsDialog::cancelClicked()
|
jtkorhonen@0
|
155 {
|
jtkorhonen@0
|
156 close();
|
jtkorhonen@0
|
157 }
|
jtkorhonen@0
|
158
|
jtkorhonen@30
|
159 void SettingsDialog::browseDirAndSetCombo(QComboBox *combo)
|
jtkorhonen@0
|
160 {
|
jtkorhonen@0
|
161 QString dir;
|
jtkorhonen@0
|
162 QString startDir;
|
jtkorhonen@0
|
163 QString system;
|
jtkorhonen@0
|
164
|
jtkorhonen@0
|
165 system = getSystem();
|
jtkorhonen@0
|
166 if ((system == "Linux") || (system == "Mac"))
|
jtkorhonen@0
|
167 {
|
jtkorhonen@0
|
168 startDir = QDir::homePath();
|
jtkorhonen@0
|
169 }
|
jtkorhonen@0
|
170 else
|
jtkorhonen@0
|
171 {
|
jtkorhonen@0
|
172 startDir = "c:\\";
|
jtkorhonen@0
|
173 }
|
jtkorhonen@0
|
174
|
jtkorhonen@0
|
175 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
|
jtkorhonen@0
|
176 startDir,
|
jtkorhonen@0
|
177 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
jtkorhonen@0
|
178
|
jtkorhonen@30
|
179 combo -> setItemText(0, dir + QDir::separator());
|
jtkorhonen@0
|
180 }
|
jtkorhonen@0
|
181
|
jtkorhonen@0
|
182 void SettingsDialog::browseWorkFolder()
|
jtkorhonen@0
|
183 {
|
jtkorhonen@30
|
184 browseDirAndSetCombo(workFolderCombo);
|
jtkorhonen@0
|
185 }
|
jtkorhonen@0
|
186
|
jtkorhonen@0
|
187 void SettingsDialog::browseRemoteRepo()
|
jtkorhonen@0
|
188 {
|
jtkorhonen@30
|
189 browseDirAndSetCombo(remoteRepoCombo);
|
jtkorhonen@0
|
190 }
|
jtkorhonen@0
|
191
|
jtkorhonen@0
|
192
|