~ubuntu-branches/debian/stretch/psi-plus/stretch

« back to all changes in this revision

Viewing changes to src/plugins/deprecated/yandexnarodplugin/yandexnarodmanage.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-10-23 02:42:20 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20131023024220-bk2hyoenqkwfhpgw
Tags: 0.16.242-1
* New upstream release:
  fixed the problem of initialization of private conversation when both
  sides use libotr 4.0.x. (Closes: #724880)
* Update debian/watch: sources were moved.
* Delete psi-plus-content-downloader package and update all related files.
  This plugin is in psi-plus-plugins package now.
* Update debian/control:
  - remove all currently unneeded Replaces and Breaks fields
  - add build dependency on libidn11-dev
* Update debian/rules: simplify get-orig-source section.
* Update debian/copyright:
  - update Source field due to changes in sources location
  - remove copyright holders whose code was deleted from source tree
    (bundled libidn library was removed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    yandexnarodManage
 
3
 
 
4
        Copyright (c) 2009 by Alexander Kazarin <boiler@co.ru>
 
5
                        2011 by Evgeny Khryukin
 
6
 
 
7
 ***************************************************************************
 
8
 *                                                                         *
 
9
 *   This program is free software; you can redistribute it and/or modify  *
 
10
 *   it under the terms of the GNU General Public License as published by  *
 
11
 *   the Free Software Foundation; either version 2 of the License, or     *
 
12
 *   (at your option) any later version.                                   *
 
13
 *                                                                         *
 
14
 ***************************************************************************
 
15
*/
 
16
 
 
17
#include <QClipboard>
 
18
#include <QFileDialog>
 
19
#include <QMimeData>
 
20
#include <QListWidgetItem>
 
21
#include <QMouseEvent>
 
22
#include <QMenu>
 
23
#include <QMessageBox>
 
24
#include <QDesktopServices>
 
25
 
 
26
#include "yandexnarodmanage.h"
 
27
#include "uploaddialog.h"
 
28
#include "optionaccessinghost.h"
 
29
#include "yandexnarodsettings.h"
 
30
#include "options.h"
 
31
#include "ui_yandexnarodmanage.h"
 
32
 
 
33
 
 
34
 
 
35
//------------------------------------------
 
36
//-------ListWidgetItem---------------------
 
37
//------------------------------------------
 
38
class ListWidgetItem : public QListWidgetItem
 
39
{
 
40
public:
 
41
        ListWidgetItem(const QIcon& ico, const yandexnarodNetMan::FileItem& fileitem)
 
42
                : QListWidgetItem(ico, fileitem.filename)
 
43
                , item_(fileitem)
 
44
        {
 
45
                QString toolTip = QObject::tr("Name: %1\nSize: %2\nDate prolongate: %3\nURL: %4\nPassword: %5")
 
46
                                        .arg(fileitem.filename)
 
47
                                        .arg( QString(fileitem.size).replace("&nbsp;", " ") )
 
48
                                        .arg(fileitem.date)
 
49
                                        .arg(fileitem.fileurl)
 
50
                                        .arg(fileitem.passset ? QObject::tr("Yes") : QObject::tr("No"));
 
51
                setToolTip(toolTip);
 
52
        }
 
53
 
 
54
        const yandexnarodNetMan::FileItem& fileItem() const
 
55
        {
 
56
                return item_;
 
57
        }
 
58
 
 
59
private:
 
60
        yandexnarodNetMan::FileItem item_;
 
61
};
 
62
 
 
63
 
 
64
 
 
65
 
 
66
//------------------------------------------
 
67
//-------ListWidget-------------------------
 
68
//------------------------------------------
 
69
ListWidget::ListWidget(QWidget* p)
 
70
        : QListWidget(p)
 
71
{
 
72
}
 
73
 
 
74
QStringList ListWidget::mimeTypes() const
 
75
{
 
76
        return QStringList() << "text/plain";
 
77
}
 
78
 
 
79
QMimeData* ListWidget::mimeData(const QList<QListWidgetItem *> items) const
 
80
{
 
81
        if(items.isEmpty())
 
82
                return 0;
 
83
 
 
84
        QMimeData* d = new QMimeData();
 
85
        QString text;
 
86
        foreach(QListWidgetItem *i, items) {
 
87
                text += static_cast<ListWidgetItem*>(i)->fileItem().fileurl + "\n";
 
88
        }
 
89
        d->setText(text);
 
90
 
 
91
        return d;
 
92
}
 
93
 
 
94
void ListWidget::mousePressEvent(QMouseEvent *event)
 
95
{
 
96
        QListWidget::mousePressEvent(event);
 
97
        if(event->button() == Qt::RightButton) {
 
98
                QListWidgetItem *lwi = itemAt(event->pos());
 
99
                if(lwi) {
 
100
                        ListWidgetItem *it = static_cast<ListWidgetItem*>(lwi);
 
101
                        emit menu(it->fileItem());
 
102
                        event->accept();
 
103
                }
 
104
        }
 
105
}
 
106
 
 
107
static QStringList files(const QMimeData *md)
 
108
{
 
109
        QString str = QFile::decodeName(QByteArray::fromPercentEncoding(md->data("text/uri-list")));
 
110
        QRegExp re("file://(.+)");
 
111
        QStringList files;
 
112
        int index = re.indexIn(str);
 
113
        while(index != -1) {
 
114
                files.append(re.cap(1).trimmed());
 
115
                index = re.indexIn(str, index+1);
 
116
        }
 
117
        return files;
 
118
}
 
119
 
 
120
void ListWidget::dragEnterEvent(QDragEnterEvent *event)
 
121
{
 
122
        const QMimeData *md = event->mimeData();
 
123
        QStringList list = files(md);
 
124
        bool ok = false;
 
125
        if(list.size() == 1) {
 
126
                QFile file(list.takeFirst());
 
127
                if(file.exists()) {
 
128
                        ok = true;
 
129
                }
 
130
        }
 
131
        if(ok) {
 
132
                event->acceptProposedAction();
 
133
        }
 
134
}
 
135
 
 
136
void ListWidget::dropEvent(QDropEvent *event)
 
137
{
 
138
        QStringList list = files(event->mimeData());
 
139
        if(list.size() == 1) {
 
140
                const QString path = list.takeFirst();
 
141
                QFile file(path);
 
142
                if(file.exists())
 
143
                        emit uploadFile(path);
 
144
        }
 
145
 
 
146
        event->setDropAction(Qt::IgnoreAction);
 
147
        event->accept();
 
148
}
 
149
 
 
150
 
 
151
//------------------------------------------
 
152
//-------yandexnarodManage------------------
 
153
//------------------------------------------
 
154
yandexnarodManage::yandexnarodManage(QWidget* p)
 
155
        : QDialog(p, Qt::Window)
 
156
        , ui_(new Ui::yandexnarodManageClass)
 
157
{
 
158
        ui_->setupUi(this);
 
159
        setWindowTitle(tr("Yandex.Narod file manager"));
 
160
        setWindowIcon(QIcon(":/icons/yandexnarodplugin.png"));
 
161
        ui_->frameProgress->hide();
 
162
        ui_->frameFileActions->hide();
 
163
        ui_->listWidget->clear();
 
164
 
 
165
        ui_->btnOpenBrowser->setIcon(qApp->style()->standardIcon(QStyle::SP_BrowserReload));
 
166
 
 
167
        newNetMan();
 
168
 
 
169
        QPixmap iconimage(":/icons/yandexnarod-icons-files.png");
 
170
        for (int i=0; i<(iconimage.width()/16); i++) {
 
171
                QIcon icon(iconimage.copy((i*16),0,16,16));
 
172
                fileicons.append(icon);
 
173
        }
 
174
 
 
175
        fileiconstyles["b-icon-music"] = 0;
 
176
        fileiconstyles["b-icon-video"] = 1;
 
177
        fileiconstyles["b-icon-arc"] = 2;
 
178
        fileiconstyles["b-icon-doc"] = 3;
 
179
        fileiconstyles["b-icon-soft"] = 4;
 
180
        fileiconstyles["b-icon-unknown"] = 5;
 
181
        fileiconstyles["b-icon-picture"] = 14;
 
182
 
 
183
        Options* o = Options::instance();
 
184
        int h = o->getOption(CONST_HEIGHT, 200).toInt();
 
185
        int w = o->getOption(CONST_WIDTH, 300).toInt();
 
186
 
 
187
        resize(w, h);
 
188
 
 
189
        setAttribute(Qt::WA_QuitOnClose, false);
 
190
        setAttribute(Qt::WA_DeleteOnClose, true);
 
191
 
 
192
        connect(ui_->listWidget, SIGNAL(menu(yandexnarodNetMan::FileItem)), SLOT(doMenu(yandexnarodNetMan::FileItem)));
 
193
        connect(ui_->listWidget, SIGNAL(uploadFile(QString)), this, SLOT(uploadFile(QString)), Qt::QueuedConnection);
 
194
}
 
195
 
 
196
yandexnarodManage::~yandexnarodManage()
 
197
{
 
198
        Options* o = Options::instance();
 
199
        o->setOption(CONST_HEIGHT, height());
 
200
        o->setOption(CONST_WIDTH, width());
 
201
 
 
202
        delete ui_;
 
203
}
 
204
 
 
205
void yandexnarodManage::newNetMan()
 
206
{
 
207
        netman = new yandexnarodNetMan(this);
 
208
        connect(netman, SIGNAL(statusText(QString)), ui_->labelStatus, SLOT(setText(QString)));
 
209
        connect(netman, SIGNAL(newFileItem(yandexnarodNetMan::FileItem)), this, SLOT(newFileItem(yandexnarodNetMan::FileItem)));
 
210
        connect(netman, SIGNAL(finished()), this, SLOT(netmanFinished()));
 
211
}
 
212
 
 
213
void yandexnarodManage::newFileItem(yandexnarodNetMan::FileItem fileitem)
 
214
{
 
215
        int iconnum = 5;
 
216
        QString fileiconname = fileitem.fileicon.replace("-old", "");
 
217
        if (fileiconstyles.contains(fileiconname))
 
218
                iconnum = fileiconstyles[fileiconname];
 
219
 
 
220
        QListWidgetItem *listitem = new ListWidgetItem(fileicons[iconnum], fileitem);
 
221
        ui_->listWidget->addItem(listitem);
 
222
}
 
223
 
 
224
void yandexnarodManage::netmanPrepare()
 
225
{
 
226
        ui_->frameProgress->show();
 
227
        ui_->labelStatus->clear();
 
228
        ui_->frameFileActions->hide();
 
229
        ui_->btnReload->setEnabled(false);
 
230
}
 
231
 
 
232
void yandexnarodManage::netmanFinished()
 
233
{
 
234
        ui_->btnReload->setEnabled(true);
 
235
}
 
236
 
 
237
void yandexnarodManage::on_btnReload_clicked()
 
238
{
 
239
        ui_->listWidget->clear();
 
240
        netmanPrepare();
 
241
        netman->startGetFilelist();
 
242
}
 
243
 
 
244
void yandexnarodManage::on_btnDelete_clicked()
 
245
{
 
246
        QList<yandexnarodNetMan::FileItem> out;
 
247
        foreach(QListWidgetItem* i, ui_->listWidget->selectedItems()) {
 
248
                ListWidgetItem* lwi = static_cast<ListWidgetItem*>(i);
 
249
                yandexnarodNetMan::FileItem &f = const_cast<yandexnarodNetMan::FileItem&>(lwi->fileItem());
 
250
                if(!f.deleted) {
 
251
                        out.append(f);
 
252
                        f.deleted = true;
 
253
                }
 
254
        }
 
255
        if(out.isEmpty())
 
256
                return;
 
257
 
 
258
        int rez = QMessageBox::question(this, tr("Delete file(s)"), tr("Are you sure?"), QMessageBox::Ok | QMessageBox::Cancel);
 
259
        if(rez == QMessageBox::Cancel)
 
260
                return;
 
261
 
 
262
        foreach(QListWidgetItem* i, ui_->listWidget->selectedItems()) {
 
263
                i->setIcon(fileicons[15]);
 
264
        }
 
265
        netmanPrepare();
 
266
        netman->startDelFiles(out);
 
267
}
 
268
 
 
269
void yandexnarodManage::on_btnProlong_clicked()
 
270
{
 
271
        netmanPrepare();
 
272
        QList<yandexnarodNetMan::FileItem> out;
 
273
        foreach(QListWidgetItem* i, ui_->listWidget->selectedItems()) {
 
274
                ListWidgetItem* lwi = static_cast<ListWidgetItem*>(i);
 
275
                yandexnarodNetMan::FileItem f = lwi->fileItem();
 
276
                if(f.prolong() < 45) {
 
277
                        out.append(f);
 
278
                }
 
279
        }
 
280
        netman->startProlongFiles(out);
 
281
}
 
282
 
 
283
void yandexnarodManage::on_btnClearCookies_clicked()
 
284
{
 
285
        netman->disconnect();
 
286
        netman->deleteLater();
 
287
 
 
288
        Options::instance()->saveCookies(QList<QNetworkCookie>());
 
289
 
 
290
        newNetMan();
 
291
        ui_->frameProgress->show();
 
292
        ui_->labelStatus->setText(O_M(MRemoveCookie));
 
293
}
 
294
 
 
295
void yandexnarodManage::on_btnOpenBrowser_clicked()
 
296
{
 
297
        QDesktopServices::openUrl(QUrl("http://narod.yandex.ru/disk/all/"));
 
298
}
 
299
 
 
300
void yandexnarodManage::on_listWidget_pressed(QModelIndex)
 
301
{
 
302
        if (ui_->frameFileActions->isHidden())
 
303
                ui_->frameFileActions->show();
 
304
 
 
305
        bool prolong = false;
 
306
        foreach(QListWidgetItem* i, ui_->listWidget->selectedItems()) {
 
307
                ListWidgetItem* lwi = static_cast<ListWidgetItem*>(i);
 
308
                if(lwi->fileItem().prolong() < 45) {
 
309
                        prolong = true;
 
310
                        break;
 
311
                }
 
312
        }
 
313
        ui_->btnProlong->setEnabled(prolong);
 
314
}
 
315
 
 
316
void yandexnarodManage::on_btnClipboard_clicked()
 
317
{
 
318
        QStringList text;
 
319
        foreach(QListWidgetItem* i, ui_->listWidget->selectedItems()) {
 
320
                text << static_cast<ListWidgetItem*>(i)->fileItem().fileurl;
 
321
        }
 
322
        copyToClipboard(text.join("\n"));
 
323
}
 
324
 
 
325
void yandexnarodManage::copyToClipboard(const QString &text)
 
326
{
 
327
        QClipboard *clipboard = QApplication::clipboard();
 
328
        clipboard->setText(text);
 
329
}
 
330
 
 
331
void yandexnarodManage::on_btnUpload_clicked()
 
332
{
 
333
        QString filePath = QFileDialog::getOpenFileName(this, O_M(MChooseFile), Options::instance()->getOption(CONST_LAST_FOLDER).toString());
 
334
 
 
335
        if (!filePath.isEmpty()) {
 
336
                QFileInfo fi(filePath);
 
337
                Options::instance()->setOption(CONST_LAST_FOLDER, fi.dir().path());
 
338
 
 
339
                uploadFile(filePath);
 
340
        }
 
341
}
 
342
 
 
343
void yandexnarodManage::uploadFile(const QString &path)
 
344
{
 
345
        uploadDialog* uploadwidget = new uploadDialog(this);
 
346
        connect(uploadwidget, SIGNAL(canceled()), this, SLOT(netmanFinished()));
 
347
        connect(uploadwidget, SIGNAL(finished()), this, SLOT(netmanFinished()));
 
348
        uploadwidget->show();
 
349
        uploadwidget->start(path);
 
350
}
 
351
 
 
352
void yandexnarodManage::doMenu(const yandexnarodNetMan::FileItem &it)
 
353
{
 
354
        QMenu m;
 
355
        QList<QAction*> actions;
 
356
        QAction *act = new QAction(tr("Set password"), &m);
 
357
        act->setVisible(!it.passset);
 
358
        act->setData(1);
 
359
        actions << act;
 
360
        act = new QAction(tr("Remove password"), &m);
 
361
        act->setVisible(it.passset);
 
362
        act->setData(2);
 
363
        actions << act;
 
364
        act = new QAction(tr("Copy URL"), &m);
 
365
        act->setData(3);
 
366
        actions << act;
 
367
        act = new QAction(tr("Prolongate"), &m);
 
368
        act->setData(4);
 
369
        act->setEnabled(it.prolong() < 45);
 
370
        actions << act;
 
371
        m.addActions(actions);
 
372
        QAction* ret = m.exec(QCursor::pos());
 
373
        if(ret) {
 
374
                switch(ret->data().toInt()) {
 
375
                case 1:
 
376
                        netman->startSetPass(it);
 
377
                        break;
 
378
                case 2:
 
379
                        netman->startRemovePass(it);
 
380
                        break;
 
381
                case 3:
 
382
                        copyToClipboard(it.fileurl);
 
383
                        break;
 
384
                case 4:
 
385
                        netman->startProlongFiles(QList<yandexnarodNetMan::FileItem>() << it);
 
386
                default:
 
387
                        break;
 
388
                }
 
389
        }
 
390
}
 
391