jtkorhonen@0
|
1 //** Copyright (C) Jari Korhonen, 2010 (under lgpl)
|
jtkorhonen@0
|
2
|
jtkorhonen@0
|
3 #include "settingsdialog.h"
|
jtkorhonen@0
|
4
|
jtkorhonen@0
|
5 #include <QHBoxLayout>
|
jtkorhonen@0
|
6 #include <QVBoxLayout>
|
jtkorhonen@0
|
7
|
jtkorhonen@0
|
8 SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent)
|
jtkorhonen@0
|
9 {
|
jtkorhonen@0
|
10 QPushButton *okButton;
|
jtkorhonen@0
|
11 QPushButton *cancelButton;
|
jtkorhonen@0
|
12
|
jtkorhonen@0
|
13 mainWnd = (MainWindow *) parent;
|
jtkorhonen@0
|
14
|
jtkorhonen@0
|
15 userInfoLabel = new QLabel(tr("User info for commits, e.g. John Smith <john.smith@mail.com>"));
|
jtkorhonen@0
|
16 userInfoLineEdit = new QLineEdit(mainWnd->userInfo);
|
jtkorhonen@0
|
17 userInfoLabel -> setBuddy(userInfoLineEdit);
|
jtkorhonen@0
|
18
|
jtkorhonen@0
|
19 remoteRepoLabel = new QLabel(tr("Remote repository path, e.g. http://192.168.1.10:8000/ or /home/mike/anotherrepo/ or c:\\anotherrepo\\"));
|
jtkorhonen@0
|
20 remoteRepoLineEdit = new QLineEdit(mainWnd->remoteRepoPath);
|
jtkorhonen@0
|
21 remoteRepoLabel -> setBuddy(remoteRepoLineEdit);
|
jtkorhonen@0
|
22 remoteRepoBrowseButton = new QPushButton(tr("Browse..."));
|
jtkorhonen@0
|
23
|
jtkorhonen@0
|
24 workFolderLabel = new QLabel(tr("Local work folder path, e.g. /home/mike/work/ or c:\\mike\\work\\"));
|
jtkorhonen@0
|
25 workFolderLineEdit = new QLineEdit(mainWnd -> workFolderPath);
|
jtkorhonen@0
|
26 workFolderLabel -> setBuddy(workFolderLineEdit);
|
jtkorhonen@0
|
27 workFolderBrowseButton = new QPushButton(tr("Browse..."));
|
jtkorhonen@0
|
28
|
jtkorhonen@0
|
29 okButton = new QPushButton(tr("Ok"));
|
jtkorhonen@0
|
30 cancelButton = new QPushButton(tr("Cancel"));
|
jtkorhonen@0
|
31
|
jtkorhonen@0
|
32 QHBoxLayout *btnLayout = new QHBoxLayout;
|
jtkorhonen@0
|
33 btnLayout -> addWidget(okButton);
|
jtkorhonen@0
|
34 btnLayout -> addWidget(cancelButton);
|
jtkorhonen@0
|
35 btnLayout -> addStretch();
|
jtkorhonen@0
|
36
|
jtkorhonen@0
|
37 QHBoxLayout *workFolderLayout = new QHBoxLayout;
|
jtkorhonen@0
|
38 workFolderLayout -> addWidget(workFolderLineEdit);
|
jtkorhonen@0
|
39 workFolderLayout -> addWidget(workFolderBrowseButton);
|
jtkorhonen@0
|
40
|
jtkorhonen@0
|
41 QHBoxLayout *remoteRepoLayout = new QHBoxLayout;
|
jtkorhonen@0
|
42 remoteRepoLayout -> addWidget(remoteRepoLineEdit);
|
jtkorhonen@0
|
43 remoteRepoLayout -> addWidget(remoteRepoBrowseButton);
|
jtkorhonen@0
|
44
|
jtkorhonen@0
|
45 QVBoxLayout *mainLayout = new QVBoxLayout;
|
jtkorhonen@0
|
46
|
jtkorhonen@0
|
47 mainLayout -> addWidget(userInfoLabel);
|
jtkorhonen@0
|
48 mainLayout -> addWidget(userInfoLineEdit);
|
jtkorhonen@0
|
49
|
jtkorhonen@0
|
50 mainLayout -> addWidget(remoteRepoLabel);
|
jtkorhonen@0
|
51 mainLayout -> addLayout(remoteRepoLayout);
|
jtkorhonen@0
|
52
|
jtkorhonen@0
|
53 mainLayout -> addWidget(workFolderLabel);
|
jtkorhonen@0
|
54 mainLayout -> addLayout(workFolderLayout);
|
jtkorhonen@0
|
55
|
jtkorhonen@0
|
56 mainLayout -> addLayout(btnLayout);
|
jtkorhonen@0
|
57
|
jtkorhonen@0
|
58 setLayout(mainLayout);
|
jtkorhonen@0
|
59
|
jtkorhonen@0
|
60 connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
|
jtkorhonen@0
|
61 connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
jtkorhonen@0
|
62 connect(workFolderBrowseButton, SIGNAL(clicked()), this, SLOT(browseWorkFolder()));
|
jtkorhonen@0
|
63 connect(remoteRepoBrowseButton, SIGNAL(clicked()), this, SLOT(browseRemoteRepo()));
|
jtkorhonen@0
|
64 }
|
jtkorhonen@0
|
65
|
jtkorhonen@0
|
66 #define EMPTY_DIR 2
|
jtkorhonen@0
|
67
|
jtkorhonen@0
|
68 void SettingsDialog::okClicked()
|
jtkorhonen@0
|
69 {
|
jtkorhonen@0
|
70 mainWnd -> firstStart = false;
|
jtkorhonen@0
|
71 mainWnd -> userInfo = userInfoLineEdit->text();
|
jtkorhonen@0
|
72 mainWnd -> remoteRepoPath = remoteRepoLineEdit->text();
|
jtkorhonen@0
|
73 mainWnd -> workFolderPath = workFolderLineEdit -> text();
|
jtkorhonen@0
|
74 mainWnd -> writeSettings();
|
jtkorhonen@0
|
75 mainWnd -> enableDisableActions();
|
jtkorhonen@0
|
76 mainWnd -> hgStat();
|
jtkorhonen@0
|
77 mainWnd -> hgExp -> setWorkFolderAndRepoNames(mainWnd -> workFolderPath, mainWnd -> remoteRepoPath);
|
jtkorhonen@0
|
78
|
jtkorhonen@0
|
79 QDir dir(mainWnd -> workFolderPath);
|
jtkorhonen@0
|
80 if (dir.exists(mainWnd -> workFolderPath))
|
jtkorhonen@0
|
81 {
|
jtkorhonen@0
|
82 uint cnt = dir.count();
|
jtkorhonen@0
|
83 if (cnt == EMPTY_DIR)
|
jtkorhonen@0
|
84 {
|
jtkorhonen@0
|
85 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
|
86 }
|
jtkorhonen@0
|
87 else
|
jtkorhonen@0
|
88 {
|
jtkorhonen@0
|
89 QString repoPath = mainWnd -> workFolderPath + getHgDirName();
|
jtkorhonen@0
|
90 QDir repoDir(repoPath);
|
jtkorhonen@0
|
91 if (!repoDir.exists())
|
jtkorhonen@0
|
92 {
|
jtkorhonen@0
|
93 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
|
94 }
|
jtkorhonen@0
|
95 }
|
jtkorhonen@0
|
96 }
|
jtkorhonen@0
|
97
|
jtkorhonen@0
|
98
|
jtkorhonen@0
|
99 close();
|
jtkorhonen@0
|
100 }
|
jtkorhonen@0
|
101
|
jtkorhonen@0
|
102
|
jtkorhonen@0
|
103 void SettingsDialog::cancelClicked()
|
jtkorhonen@0
|
104 {
|
jtkorhonen@0
|
105 close();
|
jtkorhonen@0
|
106 }
|
jtkorhonen@0
|
107
|
jtkorhonen@0
|
108
|
jtkorhonen@0
|
109 void SettingsDialog::browseDirAndSetLineEdit(QLineEdit *lineEdit)
|
jtkorhonen@0
|
110 {
|
jtkorhonen@0
|
111 QString dir;
|
jtkorhonen@0
|
112 QString startDir;
|
jtkorhonen@0
|
113 QString system;
|
jtkorhonen@0
|
114
|
jtkorhonen@0
|
115 system = getSystem();
|
jtkorhonen@0
|
116 if ((system == "Linux") || (system == "Mac"))
|
jtkorhonen@0
|
117 {
|
jtkorhonen@0
|
118 startDir = QDir::homePath();
|
jtkorhonen@0
|
119 }
|
jtkorhonen@0
|
120 else
|
jtkorhonen@0
|
121 {
|
jtkorhonen@0
|
122 startDir = "c:\\";
|
jtkorhonen@0
|
123 }
|
jtkorhonen@0
|
124
|
jtkorhonen@0
|
125 dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
|
jtkorhonen@0
|
126 startDir,
|
jtkorhonen@0
|
127 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
jtkorhonen@0
|
128
|
jtkorhonen@0
|
129 lineEdit->setText(dir + QDir::separator());
|
jtkorhonen@0
|
130 }
|
jtkorhonen@0
|
131
|
jtkorhonen@0
|
132 void SettingsDialog::browseWorkFolder()
|
jtkorhonen@0
|
133 {
|
jtkorhonen@0
|
134 browseDirAndSetLineEdit(workFolderLineEdit);
|
jtkorhonen@0
|
135 }
|
jtkorhonen@0
|
136
|
jtkorhonen@0
|
137 void SettingsDialog::browseRemoteRepo()
|
jtkorhonen@0
|
138 {
|
jtkorhonen@0
|
139 browseDirAndSetLineEdit(remoteRepoLineEdit);
|
jtkorhonen@0
|
140 }
|
jtkorhonen@0
|
141
|
jtkorhonen@0
|
142
|