-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathremotetreesdialog.cpp
More file actions
157 lines (137 loc) · 5.03 KB
/
remotetreesdialog.cpp
File metadata and controls
157 lines (137 loc) · 5.03 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
#include "remotetreesdialog.h"
#include "ui_remotetreesdialog.h"
#include "pcloudwindow.h"
#include <QInputDialog>
psync_folderid_t cryptoFldrId;
QIcon pFldrIcon;
RemoteTreesDialog::RemoteTreesDialog(QString curritem, QWidget *parent) :
QDialog(parent),
ui(new Ui::RemoteTreesDialog)
{
ui->setupUi(this);
pFldrIcon.addPixmap(QPixmap(":/16x16/images/16x16/folder-p.png"), QIcon::Normal);
pFldrIcon.addPixmap(QPixmap(":/16x16/images/16x16/folder-p-w.png"), QIcon::Selected);
cryptoFldrId = psync_crypto_folderid();
qDebug()<<"RemoteTreesDialog"<<cryptoFldrId;
if (parent != NULL)
this->setParent(parent);
if(!curritem.isNull())
this->currentItemPath = curritem;
ui->widget_fldrName->setVisible(false); /// for acceptshare - to edin fldr name
this->init();
connect(ui->btnAccept, SIGNAL(clicked()), this,SLOT(setSelectedFolder()));
connect(ui->btnReject, SIGNAL(clicked()),this,SLOT(hide()));
connect(ui->btnNewFolder, SIGNAL(clicked()), this, SLOT(newRemoteFldr()));
this->setWindowIcon(QIcon(WINDOW_ICON));
this->setWindowTitle("Choose pCloud Drive Folder");
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
}
static QList<QTreeWidgetItem *> listRemoteFldrs(QString parentPath)
{
QList<QTreeWidgetItem *> items;
pfolder_list_t *res = psync_list_remote_folder_by_path(parentPath.toUtf8(),PLIST_FOLDERS);
if (res != NULL)
{
for(uint i = 0; i < res->entrycnt; i++)
{
if(cryptoFldrId != PSYNC_CRYPTO_INVALID_FOLDERID && res->entries[i].folder.folderid == cryptoFldrId)
continue;
QString path = parentPath;
if (parentPath != "/")
path.append("/").append(res->entries[i].name);
else
path.append(res->entries[i].name);
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem*)0, QStringList(res->entries[i].name));
item->setIcon(0, pFldrIcon);
item->setData(0, Qt::UserRole, path);
item->setData(1, Qt::UserRole, (quint64)res->entries[i].folder.folderid);
item->addChildren(listRemoteFldrs(path));
items.append(item);
}
}
free(res);
return items;
}
void RemoteTreesDialog::init()
{
if(ui->treeRemoteFldrs->topLevelItemCount())
ui->treeRemoteFldrs->clear();
QList<QTreeWidgetItem *> items;
ui->treeRemoteFldrs->setColumnCount(1);
ui->treeRemoteFldrs->setHeaderLabels(QStringList("Name"));
QString root = "/";
QTreeWidgetItem *rootItem = new QTreeWidgetItem(QStringList(root)); // ??
rootItem->setIcon(0, pFldrIcon);
rootItem->setData(0, Qt::UserRole,root); //set path
rootItem->setData(1,Qt::UserRole,0); //id
ui->treeRemoteFldrs->insertTopLevelItem(0,rootItem);
ui->treeRemoteFldrs->setCurrentItem(rootItem);
this->root = rootItem;
items = listRemoteFldrs(root);
rootItem->addChildren(items);
ui->treeRemoteFldrs->expandItem(rootItem);
ui->treeRemoteFldrs->setSortingEnabled(true);
ui->treeRemoteFldrs->sortByColumn(0, Qt::AscendingOrder);
}
RemoteTreesDialog::~RemoteTreesDialog()
{
delete ui;
}
void RemoteTreesDialog::showEvent(QShowEvent *event)
{
ui->treeRemoteFldrs->setCurrentItem(this->root);
event->accept();
}
QString RemoteTreesDialog::newRemoteFldr()
{
QString dirname = QInputDialog::getText(this, tr("Create New Folder"), tr("Folder name"));
if(dirname.isEmpty())
return "";
QString parentpath = ui->treeRemoteFldrs->currentItem()->data(0, Qt::UserRole).toString();
if(parentpath != "/")
parentpath.append("/");
parentpath.append(dirname);
char *err = NULL;
psync_create_remote_folder_by_path(parentpath.toUtf8(),&err);
if (err)
{
QMessageBox::critical(this,"pCloud",trUtf8(err));
return "";
}
free(err);
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidgetItem*)0,QStringList(dirname));
item->setIcon(0, pFldrIcon);
item->setData(0,Qt::UserRole, parentpath);
ui->treeRemoteFldrs->currentItem()->insertChild(0,item);
ui->treeRemoteFldrs->setCurrentItem(item);
ui->treeRemoteFldrs->scrollToItem(item);
if(this->parent() != NULL && this->parent()->objectName() == "addSyncDialog")
{
QObject *obj = this->parent();
addSyncDialog *parent = qobject_cast<addSyncDialog*>(obj);
parent->newRemoteFldr(dirname);
}
return dirname;
}
void RemoteTreesDialog::setSelectedFolder()
{
if(!ui->treeRemoteFldrs->currentItem())
{
QMessageBox::warning(this,"pCloud",trUtf8("No remote folder is selected. Please click on a folder to select"));
return;
}
else
{
fldrid = ui->treeRemoteFldrs->currentItem()->data(1,Qt::UserRole).toULongLong();
fldrPath = ui->treeRemoteFldrs->currentItem()->data(0,Qt::UserRole).toString();
this->accept();
}
}
quint64 RemoteTreesDialog::getFldrid()
{
return this->fldrid;
}
QString RemoteTreesDialog::getFldrPath()
{
return this->fldrPath;
}