forked from owncloud/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharedialog.cpp
More file actions
160 lines (130 loc) · 4.86 KB
/
Copy pathsharedialog.cpp
File metadata and controls
160 lines (130 loc) · 4.86 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
/*
* Copyright (C) by Roeland Jago Douma <roeland@famdouma.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "sharedialog.h"
#include "sharelinkwidget.h"
#include "shareusergroupwidget.h"
#include "ui_sharedialog.h"
#include "account.h"
#include "configfile.h"
#include "theme.h"
#include "thumbnailjob.h"
#include <QFileInfo>
#include <QFileIconProvider>
#include <QDebug>
#include <QPushButton>
#include <QFrame>
namespace OCC {
ShareDialog::ShareDialog(AccountPtr account, const QString &sharePath, const QString &localPath, bool resharingAllowed, QWidget *parent) :
QDialog(parent),
_ui(new Ui::ShareDialog),
_account(account),
_sharePath(sharePath),
_localPath(localPath),
_resharingAllowed(resharingAllowed),
_linkWidget(NULL),
_userGroupWidget(NULL)
{
setAttribute(Qt::WA_DeleteOnClose);
setObjectName("SharingDialog"); // required as group for saveGeometry call
_ui->setupUi(this);
QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close);
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
// Because people press enter in the dialog and we don't want to close for that
closeButton->setDefault(false);
closeButton->setAutoDefault(false);
// Set icon
QFileInfo f_info(_localPath);
QFileIconProvider icon_provider;
QIcon icon = icon_provider.icon(f_info);
_ui->label_icon->setPixmap(icon.pixmap(40,40));
// Set filename
QFileInfo lPath(_localPath);
QString fileName = lPath.fileName();
_ui->label_name->setText(tr("%1").arg(fileName));
QFont f( _ui->label_name->font());
f.setPointSize( f.pointSize() * 1.4 );
_ui->label_name->setFont( f );
_ui->label_sharePath->setWordWrap(true);
QString ocDir(_sharePath);
ocDir.truncate(ocDir.length()-fileName.length());
ocDir.replace(QRegExp("^/*"), "");
ocDir.replace(QRegExp("/*$"), "");
// Laying this out is complex because sharePath
// may be in use or not.
_ui->gridLayout->removeWidget(_ui->label_sharePath);
_ui->gridLayout->removeWidget(_ui->label_name);
if( ocDir.isEmpty() ) {
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 2, 1);
_ui->label_sharePath->setText(QString());
} else {
_ui->gridLayout->addWidget(_ui->label_name, 0, 1, 1, 1);
_ui->gridLayout->addWidget(_ui->label_sharePath, 1, 1, 1, 1);
_ui->label_sharePath->setText(tr("Folder: %2").arg(ocDir));
}
this->setWindowTitle(tr("%1 Sharing").arg(Theme::instance()->appNameGUI()));
if (!account->capabilities().shareAPI()) {
_ui->shareWidgetsLayout->addWidget(new QLabel(tr("The server does not allow sharing")));
return;
}
bool autoShare = true;
// We only do user/group sharing from 8.2.0
if (account->serverVersionInt() >= ((8 << 16) + (2 << 8))) {
_userGroupWidget = new ShareUserGroupWidget(account, sharePath, localPath, resharingAllowed, this);
_ui->shareWidgetsLayout->addWidget(_userGroupWidget);
QFrame *hline = new QFrame(this);
hline->setFrameShape(QFrame::HLine);
QPalette p = palette();
// Make the line softer:
p.setColor(QPalette::Foreground, QColor::fromRgba((p.color(QPalette::Foreground).rgba() & 0x00ffffff) | 0x50000000));
hline->setPalette(p);
_ui->shareWidgetsLayout->addWidget(hline);
autoShare = false;
}
_linkWidget = new ShareLinkWidget(account, sharePath, localPath, resharingAllowed, autoShare, this);
_linkWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
_ui->shareWidgetsLayout->addWidget(_linkWidget);
}
ShareDialog::~ShareDialog()
{
delete _ui;
}
void ShareDialog::done( int r ) {
ConfigFile cfg;
cfg.saveGeometry(this);
QDialog::done(r);
}
void ShareDialog::getShares()
{
if (QFileInfo(_localPath).isFile()) {
ThumbnailJob *job = new ThumbnailJob(_sharePath, _account, this);
connect(job, SIGNAL(jobFinished(int, QByteArray)), SLOT(slotThumbnailFetched(int, QByteArray)));
job->start();
}
if (_linkWidget) {
_linkWidget->getShares();
}
if (_userGroupWidget != NULL) {
_userGroupWidget->getShares();
}
}
void ShareDialog::slotThumbnailFetched(const int &statusCode, const QByteArray &reply)
{
if (statusCode != 200) {
qDebug() << Q_FUNC_INFO << "Status code: " << statusCode;
return;
}
QPixmap p;
p.loadFromData(reply, "PNG");
_ui->label_icon->setPixmap(p);
}
}