Browse Source

Create basic cookies management dialog

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago
parent
commit
c982813acb
  1. 13
      src/base/net/downloadmanager.cpp
  2. 2
      src/base/net/downloadmanager.h
  3. 89
      src/gui/cookiesdialog.cpp
  4. 61
      src/gui/cookiesdialog.h
  5. 179
      src/gui/cookiesdialog.ui
  6. 9
      src/gui/gui.pri
  7. 9
      src/gui/mainwindow.cpp
  8. 1
      src/gui/mainwindow.h
  9. 9
      src/gui/mainwindow.ui

13
src/base/net/downloadmanager.cpp

@ -75,6 +75,9 @@ namespace
Preferences::instance()->setNetworkCookies(cookies); Preferences::instance()->setNetworkCookies(cookies);
} }
using QNetworkCookieJar::allCookies;
using QNetworkCookieJar::setAllCookies;
#ifndef QBT_USES_QT5 #ifndef QBT_USES_QT5
virtual bool deleteCookie(const QNetworkCookie &cookie) virtual bool deleteCookie(const QNetworkCookie &cookie)
{ {
@ -188,6 +191,16 @@ bool DownloadManager::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList,
return m_networkManager.cookieJar()->setCookiesFromUrl(cookieList, url); return m_networkManager.cookieJar()->setCookiesFromUrl(cookieList, url);
} }
QList<QNetworkCookie> DownloadManager::allCookies() const
{
return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->allCookies();
}
void DownloadManager::setAllCookies(const QList<QNetworkCookie> &cookieList)
{
static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->setAllCookies(cookieList);
}
bool DownloadManager::deleteCookie(const QNetworkCookie &cookie) bool DownloadManager::deleteCookie(const QNetworkCookie &cookie)
{ {
return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->deleteCookie(cookie); return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->deleteCookie(cookie);

2
src/base/net/downloadmanager.h

@ -54,6 +54,8 @@ namespace Net
DownloadHandler *downloadUrl(const QString &url, bool saveToFile = false, qint64 limit = 0, bool handleRedirectToMagnet = false, const QString &userAgent = ""); DownloadHandler *downloadUrl(const QString &url, bool saveToFile = false, qint64 limit = 0, bool handleRedirectToMagnet = false, const QString &userAgent = "");
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const; QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const;
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url); bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
QList<QNetworkCookie> allCookies() const;
void setAllCookies(const QList<QNetworkCookie> &cookieList);
bool deleteCookie(const QNetworkCookie &cookie); bool deleteCookie(const QNetworkCookie &cookie);
private slots: private slots:

89
src/gui/cookiesdialog.cpp

@ -0,0 +1,89 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru>
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#include "cookiesdialog.h"
#include "base/settingsstorage.h"
#include "base/net/downloadmanager.h"
#include "guiiconprovider.h"
#include "cookiesmodel.h"
#include "ui_cookiesdialog.h"
#define SETTINGS_KEY(name) "CookiesDialog/" name
const QString KEY_GEOMETRY = SETTINGS_KEY("Geometry");
const QString KEY_COOKIESVIEWSTATE = SETTINGS_KEY("CookiesViewState");
CookiesDialog::CookiesDialog(QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::CookiesDialog)
, m_cookiesModel(new CookiesModel(Net::DownloadManager::instance()->allCookies(), this))
{
m_ui->setupUi(this);
setWindowIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies"));
m_ui->buttonAdd->setIcon(GuiIconProvider::instance()->getIcon("list-add"));
m_ui->buttonDelete->setIcon(GuiIconProvider::instance()->getIcon("list-remove"));
m_ui->treeView->setModel(m_cookiesModel);
if (m_cookiesModel->rowCount() > 0)
m_ui->treeView->selectionModel()->setCurrentIndex(
m_cookiesModel->index(0, 0),
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
restoreGeometry(SettingsStorage::instance()->loadValue(KEY_GEOMETRY).toByteArray());
m_ui->treeView->header()->restoreState(
SettingsStorage::instance()->loadValue(KEY_COOKIESVIEWSTATE).toByteArray());
}
CookiesDialog::~CookiesDialog()
{
SettingsStorage::instance()->storeValue(KEY_GEOMETRY, saveGeometry());
SettingsStorage::instance()->storeValue(
KEY_COOKIESVIEWSTATE, m_ui->treeView->header()->saveState());
delete m_ui;
}
void CookiesDialog::accept()
{
Net::DownloadManager::instance()->setAllCookies(m_cookiesModel->cookies());
QDialog::accept();
}
void CookiesDialog::onButtonAddClicked()
{
int row = m_ui->treeView->selectionModel()->currentIndex().row() + 1;
m_cookiesModel->insertRow(row);
m_ui->treeView->selectionModel()->setCurrentIndex(
m_cookiesModel->index(row, 0), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
}
void CookiesDialog::onButtonDeleteClicked()
{
m_cookiesModel->removeRow(m_ui->treeView->selectionModel()->currentIndex().row());
}

61
src/gui/cookiesdialog.h

@ -0,0 +1,61 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru>
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
#ifndef COOKIESDIALOG_H
#define COOKIESDIALOG_H
#include <QDialog>
namespace Ui
{
class CookiesDialog;
}
class CookiesModel;
class CookiesDialog : public QDialog
{
Q_OBJECT
public:
explicit CookiesDialog(QWidget *parent = 0);
~CookiesDialog();
public slots:
void accept() override;
private slots:
void onButtonAddClicked();
void onButtonDeleteClicked();
private:
Ui::CookiesDialog *m_ui;
CookiesModel *m_cookiesModel;
};
#endif // COOKIESDIALOG_H

179
src/gui/cookiesdialog.ui

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CookiesDialog</class>
<widget class="QDialog" name="CookiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>618</width>
<height>369</height>
</rect>
</property>
<property name="windowTitle">
<string>Manage Cookies</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeView" name="treeView"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonAdd">
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonDelete">
<property name="text">
<string notr="true"/>
</property>
<property name="iconSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CookiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>406</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>CookiesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>406</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonAdd</sender>
<signal>clicked()</signal>
<receiver>CookiesDialog</receiver>
<slot>onButtonAddClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>484</x>
<y>174</y>
</hint>
<hint type="destinationlabel">
<x>486</x>
<y>93</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonDelete</sender>
<signal>clicked()</signal>
<receiver>CookiesDialog</receiver>
<slot>onButtonDeleteClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>483</x>
<y>226</y>
</hint>
<hint type="destinationlabel">
<x>485</x>
<y>296</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>onButtonAddClicked()</slot>
<slot>onButtonDeleteClicked()</slot>
</slots>
</ui>

9
src/gui/gui.pri

@ -49,7 +49,8 @@ HEADERS += \
$$PWD/search/pluginsourcedlg.h \ $$PWD/search/pluginsourcedlg.h \
$$PWD/search/searchlistdelegate.h \ $$PWD/search/searchlistdelegate.h \
$$PWD/search/searchsortmodel.h \ $$PWD/search/searchsortmodel.h \
$$PWD/cookiesmodel.h $$PWD/cookiesmodel.h \
$$PWD/cookiesdialog.h
SOURCES += \ SOURCES += \
$$PWD/mainwindow.cpp \ $$PWD/mainwindow.cpp \
@ -89,7 +90,8 @@ SOURCES += \
$$PWD/search/pluginsourcedlg.cpp \ $$PWD/search/pluginsourcedlg.cpp \
$$PWD/search/searchlistdelegate.cpp \ $$PWD/search/searchlistdelegate.cpp \
$$PWD/search/searchsortmodel.cpp \ $$PWD/search/searchsortmodel.cpp \
$$PWD/cookiesmodel.cpp $$PWD/cookiesmodel.cpp \
$$PWD/cookiesdialog.cpp
win32|macx { win32|macx {
HEADERS += $$PWD/programupdater.h HEADERS += $$PWD/programupdater.h
@ -116,6 +118,7 @@ FORMS += \
$$PWD/search/searchwidget.ui \ $$PWD/search/searchwidget.ui \
$$PWD/search/pluginselectdlg.ui \ $$PWD/search/pluginselectdlg.ui \
$$PWD/search/pluginsourcedlg.ui \ $$PWD/search/pluginsourcedlg.ui \
$$PWD/search/searchtab.ui $$PWD/search/searchtab.ui \
$$PWD/cookiesdialog.ui
RESOURCES += $$PWD/about.qrc RESOURCES += $$PWD/about.qrc

9
src/gui/mainwindow.cpp

@ -91,6 +91,7 @@ void qt_mac_set_dock_menu(QMenu *menu);
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#endif #endif
#include "cookiesdialog.h"
#define TIME_TRAY_BALLOON 5000 #define TIME_TRAY_BALLOON 5000
#define PREVENT_SUSPEND_INTERVAL 60000 #define PREVENT_SUSPEND_INTERVAL 60000
@ -166,6 +167,7 @@ MainWindow::MainWindow(QWidget *parent)
actionStart_All->setIcon(GuiIconProvider::instance()->getIcon("media-playback-start")); actionStart_All->setIcon(GuiIconProvider::instance()->getIcon("media-playback-start"));
action_Import_Torrent->setIcon(GuiIconProvider::instance()->getIcon("document-import")); action_Import_Torrent->setIcon(GuiIconProvider::instance()->getIcon("document-import"));
menuAuto_Shutdown_on_downloads_completion->setIcon(GuiIconProvider::instance()->getIcon("application-exit")); menuAuto_Shutdown_on_downloads_completion->setIcon(GuiIconProvider::instance()->getIcon("application-exit"));
actionManageCookies->setIcon(GuiIconProvider::instance()->getIcon("preferences-web-browser-cookies"));
QMenu *startAllMenu = new QMenu(this); QMenu *startAllMenu = new QMenu(this);
startAllMenu->addAction(actionStart_All); startAllMenu->addAction(actionStart_All);
@ -261,6 +263,8 @@ MainWindow::MainWindow(QWidget *parent)
actionCheck_for_updates->setVisible(false); actionCheck_for_updates->setVisible(false);
#endif #endif
connect(actionManageCookies, SIGNAL(triggered()), SLOT(manageCookies()));
m_pwr = new PowerManagement(this); m_pwr = new PowerManagement(this);
preventTimer = new QTimer(this); preventTimer = new QTimer(this);
connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents())); connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents()));
@ -475,6 +479,11 @@ void MainWindow::addToolbarContextMenu()
} }
} }
void MainWindow::manageCookies()
{
CookiesDialog(this).exec();
}
void MainWindow::toolbarMenuRequested(QPoint point) void MainWindow::toolbarMenuRequested(QPoint point)
{ {
toolbarMenu->exec(toolBar->mapToGlobal(point)); toolbarMenu->exec(toolBar->mapToGlobal(point));

1
src/gui/mainwindow.h

@ -166,6 +166,7 @@ private slots:
void pythonDownloadFailure(const QString &url, const QString &error); void pythonDownloadFailure(const QString &url, const QString &error);
#endif #endif
void addToolbarContextMenu(); void addToolbarContextMenu();
void manageCookies();
private: private:
QFileSystemWatcher *executable_watcher; QFileSystemWatcher *executable_watcher;

9
src/gui/mainwindow.ui

@ -77,6 +77,7 @@
</widget> </widget>
<addaction name="actionCreate_torrent"/> <addaction name="actionCreate_torrent"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionManageCookies"/>
<addaction name="actionOptions"/> <addaction name="actionOptions"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menuAuto_Shutdown_on_downloads_completion"/> <addaction name="menuAuto_Shutdown_on_downloads_completion"/>
@ -414,6 +415,14 @@
<string>Check for Program Updates</string> <string>Check for Program Updates</string>
</property> </property>
</action> </action>
<action name="actionManageCookies">
<property name="text">
<string>Manage Cookies...</string>
</property>
<property name="toolTip">
<string>Manage stored network cookies</string>
</property>
</action>
<action name="actionExecutionLogs"> <action name="actionExecutionLogs">
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>

Loading…
Cancel
Save