-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddsyncdialog.cpp
More file actions
304 lines (279 loc) · 10.3 KB
/
addsyncdialog.cpp
File metadata and controls
304 lines (279 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "addsyncdialog.h"
#include "ui_addsyncdialog.h"
#include <QInputDialog>
#include <QMessageBox>
#include <QTextCodec>
#include <QDebug>
addSyncDialog::addSyncDialog(PCloudApp *a, PCloudWindow *w, SuggestnsBaseWin *wlcm, QWidget *parent) :
QDialog(parent),
ui(new Ui::addSyncDialog)
{
ui->setupUi(this);
app = a;
win = w;
addNewSyncsWin = wlcm;
if (addNewSyncsWin != NULL && addNewSyncsWin->getChangeItem())
remotesDialog = new RemoteTreesDialog(addNewSyncsWin->getCurrRemotePath(), this); //dialog is for changing a suggested sync
else
remotesDialog = new RemoteTreesDialog("", this); // dialog is for selecting new sync
connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addSync()));
connect(ui->btnOpenLocals, SIGNAL(clicked()), this, SLOT(chooseLocalFldr()));
connect(ui->btnOpenRemotes, SIGNAL(clicked()), this, SLOT(chooseRemoteFldr()));
//connect(ui->btnNewFldrLocal, SIGNAL(clicked()), this, SLOT(newLocalFldr()));
//connect(ui->btnNewFldrRemote, SIGNAL(clicked()), this, SLOT(newRemoteFldr()));
connect(ui->btnCancel, SIGNAL(clicked()), this, SLOT(hideDialog()));
if (addNewSyncsWin && addNewSyncsWin->getChangeItem())
{
ui->btnAdd->setText(trUtf8("Change"));
this->setWindowTitle(trUtf8("Change sync"));
localpath = addNewSyncsWin->getCurrLocalPath();
ui->btnOpenLocals->setText(getDisplFldrPath(localpath,'\\'));
remotepath = addNewSyncsWin->getCurrRemotePath();
ui->btnOpenRemotes->setText(getDisplFldrPath(remotepath, '/'));
}
else
{
this->setWindowTitle(trUtf8("Add New Sync"));
localpath = "";
remotepath = "";
}
// load();
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
this->setFixedSize(300, this->height());
}
addSyncDialog::~addSyncDialog()
{
delete ui;
delete remotesDialog;
}
void addSyncDialog::hideDialog()
{
if (addNewSyncsWin)
addNewSyncsWin->setChangeItem(false);
this->hide();
}
QString addSyncDialog::getDisplFldrPath(QString fldrpath, QChar osSep)
{
if(fldrpath.isEmpty())
return "";
if(fldrpath.length() < 40)
return fldrpath;
else
{
int namelen = fldrpath.section(osSep,-1).length();
if(namelen < 34)
return fldrpath.left(40 - namelen).append("...").append(fldrpath.right(namelen));
else
return fldrpath.left(3).append("...").append(fldrpath.right(36)); //c:\...last 36
}
}
void addSyncDialog::chooseLocalFldr()
{
QString dfltlocalpath;
if (localpath == "")
{
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
dfltlocalpath = QDir::homePath(); //lin
#else
dfltlocalpath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); //windows
#endif
}
else
dfltlocalpath = localpath;
QFileDialog* d = new QFileDialog(this);
d->setWindowIcon(QIcon(WINDOW_ICON));
d->setFileMode(QFileDialog::DirectoryOnly);
this->localpath = d->getExistingDirectory(this,"Choose Local Directory", dfltlocalpath, QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if (this->localpath.isEmpty())
return;
#ifdef Q_OS_WIN
localpath.replace("/","\\");
ui->btnOpenLocals->setText(getDisplFldrPath(localpath, '\\'));
#else
ui->btnOpenLocals->setText(getDisplFldrPath(localpath, '/'));
#endif
qDebug()<<"addSyncDialog::chooseLocalFldr"<<localpath;
/*
if(d->exec() == QFileDialog::Accepted)
{
QStringList filenames = d->selectedFiles();
if (filenames.isEmpty())
{
QMessageBox::critical(this, "pCloud", trUtf8("Please select local folder!"));
return;
}
this->localpath = filenames.at(0);
// ui->btnOpenLocals->setText(getDisplFldrPath(localpath.section("/",-1)));
for (int i = 0; i < filenames.size(); i++)
qDebug()<<"FIledialog"<< filenames.at(i);
}
else
{
this->localpath = "";
qDebug()<<"add local fodler for new sync CANCEDL";
}
*/
}
void addSyncDialog::chooseRemoteFldr()
{
this->remotesDialog->exec();
this->remotepath = remotesDialog->getFldrPath();
if (!this->remotepath.isNull())
ui->btnOpenRemotes->setText(getDisplFldrPath(remotepath,'/'));
}
void addSyncDialog::load() //obsolete
{
//remote tree
// win->initRemoteTree(ui->treeSyncRemote);
/* //local tree
model = new QFileSystemModel;
model->setReadOnly(false);
model->setFilter(QDir::NoDotAndDotDot | QDir::Dirs);
QString path = QDir::homePath();
model->setRootPath(QDir::homePath()); //currentPath
ui->treeSyncLocal->setModel(model);
ui->treeSyncLocal->sortByColumn(0,Qt::AscendingOrder);
ui->treeSyncLocal->setColumnHidden(1,true);
ui->treeSyncLocal->setColumnHidden(2, true);
ui->treeSyncLocal->setColumnHidden(3, true);
ui->treeSyncLocal->setAnimated(false);
ui->treeSyncLocal->setSortingEnabled(true);
ui->treeSyncLocal->expandAll();
if (this->addNewSyncsWin == NULL)
{
ui->treeSyncLocal->setCurrentIndex(model->index(path));
}
// not for case anything is selected
else
{ if (addNewSyncsWin->getChangeItem())
{
ui->treeSyncLocal->setCurrentIndex(model->index(addNewSyncsWin->getCurrLocalPath()));
//ui->treeSyncLocal->scrollTo(model->index(addNewSyncsWin->getCurrLocalPath()),QAbstractItemView::PositionAtCenter);
ui->comboSyncType->setCurrentIndex(addNewSyncsWin->getCurrType()-1);
}
// remote tree - add new remote Fodlers from suggestions
if (addNewSyncsWin->newRemoteFldrsLst.length() > 0)
{
for (int i = 0; i < addNewSyncsWin->newRemoteFldrsLst.length(); i++)
{
qDebug()<<addNewSyncsWin->newRemoteFldrsLst.at(i);
QTreeWidgetItem *newitem = new QTreeWidgetItem((QTreeWidgetItem*)0,QStringList(addNewSyncsWin->newRemoteFldrsLst.at(i)));
newitem->setIcon(0, QIcon(":images/images/folder-p.png"));
QString rootName = addNewSyncsWin->newRemoteFldrsLst.at(i);
rootName.insert(0,"/");
newitem->setData(0, Qt::UserRole, rootName);
QTreeWidgetItem* rootItem = ui->treeSyncRemote->topLevelItem(0);
rootItem->addChild(newitem);
}
ui->treeSyncRemote->sortByColumn(0, Qt::AscendingOrder);
}
//scroll to selected item
QString remotePath = addNewSyncsWin->getCurrRemotePath();
QString localName = addNewSyncsWin->getCurrRemotePath().section("/", -1, 1);
QList<QTreeWidgetItem*> res = ui->treeSyncRemote->findItems(localName,Qt::MatchExactly | Qt::MatchRecursive);
qDebug()<< addNewSyncsWin->getCurrRemotePath() << localName << res.length();
if (res.length() > 0)
{
for (int i = 0; i < res.length(); i++)
{
QTreeWidgetItem * current = res.at(i);
qDebug() << " find items" << res.length()<< current->data(0,Qt::UserRole);
if (remotePath == (current->data(0,Qt::UserRole).toString()))
{
ui->treeSyncRemote->setCurrentItem(current);
ui->treeSyncRemote->scrollToItem(current);
}
}
}
else
qDebug()<< "find items: 0";
}
}
*/
}
void addSyncDialog::addSync()
{
int type = PSYNC_FULL - 1; // no one-way sync anymore
/*
QString localpath,localname, remotepath;
localpath = model->filePath(ui->treeSyncLocal->currentIndex());
#ifdef Q_OS_WIN
localpath.replace("/","\\");
#endif
localname = model->fileName(ui->treeSyncLocal->currentIndex());
remotepath.append( ui->treeSyncRemote->currentItem()->data(0,Qt::UserRole).toString());
//type = ui->comboSyncType->currentIndex();
*/
if(this->localpath == "" || this->remotepath == "")
{
QMessageBox::warning(this, "pCloud Drive", trUtf8("Please select both paths!"));
return;
}
#ifdef Q_OS_WIN
if (this->localpath.startsWith("\\\\pCloud\\pCloud Drive",Qt::CaseInsensitive))
{
QMessageBox::critical(this, "pCloud Drive", trUtf8("The local folder should not be selected from a network share!\nPlease select a folder from your local drives."));
return;
}
#endif
QString localname;
if(localpath != "/")
localname = localpath.section("/",-1);
else
localname = localpath;
//qDebug()<<"TO ADD NEW SYNC : localpath = "<<localpath<< " remotepath = "<<remotepath << " type = "<<type+1<< "local folder name ="<<localname;
qDebug()<<"TO ADD NEW SYNC : localpath = "<<localpath<< " remotepath = "<<remotepath << "local folder name ="<<localname;
if(this->addNewSyncsWin)
addNewSyncsWin->addNewItem(localpath,remotepath,type);
else
{
quint32 id = psync_add_sync_by_path(localpath.toUtf8(), remotepath.toUtf8(), PSYNC_FULL);
if (id == -1)
{
qDebug()<<"err adding new sync"<<psync_get_last_error();
app->check_error();
return;
}
QAction *fldrAction = new QAction(app->emptyFldrIcon,localname,app);
fldrAction->setProperty("path",localpath);
connect(fldrAction,SIGNAL(triggered()),app, SLOT(openLocalDir()));
app->addNewFolderInMenu(fldrAction);
//syncpage->load();
win->get_sync_page()->load();
}
this->hide();
}
void addSyncDialog::showError(const QString &err)
{
QMessageBox::information(this,"", err );
}
void addSyncDialog::newRemoteFldr(QString dirname)
{
qDebug()<<"addSyncDialog"<<dirname;
if (this->addNewSyncsWin && dirname != "")
{
addNewSyncsWin->addNewRemoteFldr(dirname);
}
}
/*obsolete - old specifications
void addSyncDialog::newLocalFldr()
{
QModelIndex current = ui->treeSyncLocal->currentIndex();
QDir dir(model->filePath(current));
QString newName = "New Sync Folder";
if(dir.exists(newName))
{
int i = 1;
while(dir.exists(newName))
{
i++;
newName = "New Sync Folder(" + QString::number(i) + ")";
}
}
QModelIndex newIndex = model->mkdir(current,newName);
ui->treeSyncLocal->scrollTo(newIndex,QAbstractItemView::PositionAtCenter);
ui->treeSyncLocal->setCurrentIndex(newIndex);
model->setReadOnly(false);
}
*/