Browse Source
Implement application wide cookies management dialog. Closes #4638adaptive-webui-19844
sledgehammer999
9 years ago
20 changed files with 1281 additions and 1015 deletions
@ -0,0 +1,89 @@
@@ -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()); |
||||
} |
@ -0,0 +1,179 @@
@@ -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> |
@ -0,0 +1,178 @@
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* 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 <QDateTime> |
||||
#include "cookiesmodel.h" |
||||
|
||||
CookiesModel::CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent) |
||||
: QAbstractItemModel(parent) |
||||
, m_cookies(cookies) |
||||
{ |
||||
} |
||||
|
||||
QList<QNetworkCookie> CookiesModel::cookies() const |
||||
{ |
||||
return m_cookies; |
||||
} |
||||
|
||||
QVariant CookiesModel::headerData(int section, Qt::Orientation orientation, int role) const |
||||
{ |
||||
if ((role == Qt::DisplayRole) && (orientation == Qt::Horizontal)) { |
||||
switch (section) |
||||
{ |
||||
case COL_DOMAIN: |
||||
return tr("Domain"); |
||||
case COL_PATH: |
||||
return tr("Path"); |
||||
case COL_NAME: |
||||
return tr("Name"); |
||||
case COL_VALUE: |
||||
return tr("Value"); |
||||
case COL_EXPDATE: |
||||
return tr("Expiration Date"); |
||||
} |
||||
} |
||||
|
||||
return QVariant(); |
||||
} |
||||
|
||||
QModelIndex CookiesModel::index(int row, int column, const QModelIndex &parent) const |
||||
{ |
||||
if (parent.isValid() // no items with valid parent
|
||||
|| (row < 0) || (row >= m_cookies.size()) |
||||
|| (column < 0) || (column >= NB_COLUMNS)) |
||||
return QModelIndex(); |
||||
|
||||
return createIndex(row, column, &m_cookies[row]); |
||||
} |
||||
|
||||
QModelIndex CookiesModel::parent(const QModelIndex &index) const |
||||
{ |
||||
Q_UNUSED(index); |
||||
return QModelIndex(); |
||||
} |
||||
|
||||
int CookiesModel::rowCount(const QModelIndex &parent) const |
||||
{ |
||||
if (parent.isValid()) return 0; |
||||
|
||||
return m_cookies.size(); |
||||
} |
||||
|
||||
int CookiesModel::columnCount(const QModelIndex &parent) const |
||||
{ |
||||
Q_UNUSED(parent); |
||||
return NB_COLUMNS; |
||||
} |
||||
|
||||
QVariant CookiesModel::data(const QModelIndex &index, int role) const |
||||
{ |
||||
if (!index.isValid() || (index.row() >= m_cookies.size()) |
||||
|| ((role != Qt::DisplayRole) && (role != Qt::EditRole))) |
||||
return QVariant(); |
||||
|
||||
switch (index.column()) { |
||||
case COL_DOMAIN: |
||||
return m_cookies[index.row()].domain(); |
||||
case COL_PATH: |
||||
return m_cookies[index.row()].path(); |
||||
case COL_NAME: |
||||
return QString::fromLatin1(m_cookies[index.row()].name()); |
||||
case COL_VALUE: |
||||
return QString::fromLatin1(m_cookies[index.row()].value()); |
||||
case COL_EXPDATE: |
||||
return m_cookies[index.row()].expirationDate(); |
||||
} |
||||
|
||||
return QVariant(); |
||||
} |
||||
|
||||
bool CookiesModel::setData(const QModelIndex &index, const QVariant &value, int role) |
||||
{ |
||||
if (role != Qt::EditRole) return false; |
||||
|
||||
switch (index.column()) { |
||||
case COL_DOMAIN: |
||||
m_cookies[index.row()].setDomain(value.toString()); |
||||
break; |
||||
case COL_PATH: |
||||
m_cookies[index.row()].setPath(value.toString()); |
||||
break; |
||||
case COL_NAME: |
||||
m_cookies[index.row()].setName(value.toString().toLatin1()); |
||||
break; |
||||
case COL_VALUE: |
||||
m_cookies[index.row()].setValue(value.toString().toLatin1()); |
||||
break; |
||||
case COL_EXPDATE: |
||||
m_cookies[index.row()].setExpirationDate(value.toDateTime()); |
||||
break; |
||||
default: |
||||
return false; |
||||
} |
||||
|
||||
emit dataChanged(index, index); |
||||
return true; |
||||
} |
||||
|
||||
bool CookiesModel::insertRows(int row, int count, const QModelIndex &parent) |
||||
{ |
||||
if ((row < 0) || (row > m_cookies.size())) return false; |
||||
|
||||
QNetworkCookie newCookie; |
||||
newCookie.setExpirationDate(QDateTime::currentDateTime().addYears(99)); |
||||
|
||||
beginInsertRows(parent, row, row + count - 1); |
||||
while (count-- > 0) |
||||
m_cookies.insert(row, newCookie); |
||||
endInsertRows(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
bool CookiesModel::removeRows(int row, int count, const QModelIndex &parent) |
||||
{ |
||||
if ((m_cookies.size() == 0) |
||||
|| (row >= m_cookies.size()) |
||||
|| ((row + count) > m_cookies.size())) |
||||
return false; |
||||
|
||||
beginRemoveRows(parent, row, row + count - 1); |
||||
while (count-- > 0) |
||||
m_cookies.removeAt(row); |
||||
endRemoveRows(); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
Qt::ItemFlags CookiesModel::flags(const QModelIndex &index) const |
||||
{ |
||||
if (!index.isValid()) return 0; |
||||
|
||||
return Qt::ItemIsEditable | QAbstractItemModel::flags(index); |
||||
} |
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 COOKIESMODEL_H |
||||
#define COOKIESMODEL_H |
||||
|
||||
#include <QAbstractItemModel> |
||||
#include <QList> |
||||
#include <QNetworkCookie> |
||||
|
||||
class CookiesModel : public QAbstractItemModel |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
enum Column |
||||
{ |
||||
COL_DOMAIN, |
||||
COL_PATH, |
||||
COL_NAME, |
||||
COL_VALUE, |
||||
COL_EXPDATE, |
||||
|
||||
NB_COLUMNS |
||||
}; |
||||
|
||||
explicit CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent = 0); |
||||
|
||||
QList<QNetworkCookie> cookies() const; |
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
||||
QModelIndex parent(const QModelIndex &index) const override; |
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override; |
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override; |
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override; |
||||
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; |
||||
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; |
||||
|
||||
private: |
||||
mutable QList<QNetworkCookie> m_cookies; |
||||
}; |
||||
|
||||
#endif // COOKIESMODEL_H
|
@ -1,110 +0,0 @@
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent. |
||||
* Copyright (C) 2010 Christophe Dumez |
||||
* |
||||
* 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. |
||||
* |
||||
* Contact : chris@qbittorrent.org arnaud@qbittorrent.org |
||||
*/ |
||||
|
||||
#include "cookiesdlg.h" |
||||
#include "ui_cookiesdlg.h" |
||||
#include "guiiconprovider.h" |
||||
#include "base/net/downloadmanager.h" |
||||
|
||||
#include <QNetworkCookie> |
||||
#include <QDateTime> |
||||
|
||||
enum CookiesCols { COOKIE_KEY, COOKIE_VALUE}; |
||||
|
||||
CookiesDlg::CookiesDlg(const QUrl &url, QWidget *parent) : |
||||
QDialog(parent), |
||||
ui(new Ui::CookiesDlg) |
||||
{ |
||||
ui->setupUi(this); |
||||
// Icons
|
||||
ui->add_btn->setIcon(GuiIconProvider::instance()->getIcon("list-add")); |
||||
ui->del_btn->setIcon(GuiIconProvider::instance()->getIcon("list-remove")); |
||||
|
||||
ui->infos_lbl->setText(tr("Common keys for cookies are: '%1', '%2'.\nYou should get this information from your Web browser preferences.").arg("uid").arg("pass")); |
||||
|
||||
QList<QNetworkCookie> cookies = Net::DownloadManager::instance()->cookiesForUrl(url); |
||||
foreach (const QNetworkCookie &cookie, cookies) { |
||||
const int i = ui->cookiesTable->rowCount(); |
||||
ui->cookiesTable->setRowCount(i+1); |
||||
ui->cookiesTable->setItem(i, COOKIE_KEY, new QTableWidgetItem(QString(cookie.name()))); |
||||
ui->cookiesTable->setItem(i, COOKIE_VALUE, new QTableWidgetItem(QString(cookie.value()))); |
||||
} |
||||
} |
||||
|
||||
CookiesDlg::~CookiesDlg() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void CookiesDlg::on_add_btn_clicked() { |
||||
ui->cookiesTable->setRowCount(ui->cookiesTable->rowCount()+1); |
||||
// Edit first column
|
||||
ui->cookiesTable->editItem(ui->cookiesTable->item(ui->cookiesTable->rowCount()-1, COOKIE_KEY)); |
||||
} |
||||
|
||||
void CookiesDlg::on_del_btn_clicked() { |
||||
// Get selected cookie
|
||||
QList<QTableWidgetItem*> selection = ui->cookiesTable->selectedItems(); |
||||
if (!selection.isEmpty()) { |
||||
ui->cookiesTable->removeRow(selection.first()->row()); |
||||
} |
||||
} |
||||
|
||||
QList<QNetworkCookie> CookiesDlg::getCookies() const { |
||||
QList<QNetworkCookie> ret; |
||||
auto now = QDateTime::currentDateTime(); |
||||
for (int i=0; i<ui->cookiesTable->rowCount(); ++i) { |
||||
QString key; |
||||
if (ui->cookiesTable->item(i, COOKIE_KEY)) |
||||
key = ui->cookiesTable->item(i, COOKIE_KEY)->text().trimmed(); |
||||
QString value; |
||||
if (ui->cookiesTable->item(i, COOKIE_VALUE)) |
||||
value = ui->cookiesTable->item(i, COOKIE_VALUE)->text().trimmed(); |
||||
if (!key.isEmpty() && !value.isEmpty()) { |
||||
QNetworkCookie cookie(key.toUtf8(), value.toUtf8()); |
||||
// TODO: Delete this hack when advanced Cookie dialog will be implemented.
|
||||
cookie.setExpirationDate(now.addYears(10)); |
||||
qDebug("Cookie: %s", cookie.toRawForm().data()); |
||||
ret << cookie; |
||||
} |
||||
} |
||||
return ret; |
||||
} |
||||
|
||||
bool CookiesDlg::askForCookies(QWidget *parent, const QUrl &url, QList<QNetworkCookie> &out) |
||||
{ |
||||
CookiesDlg dlg(url, parent); |
||||
if (dlg.exec()) { |
||||
out = dlg.getCookies(); |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
@ -1,172 +0,0 @@
@@ -1,172 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>CookiesDlg</class> |
||||
<widget class="QDialog" name="CookiesDlg"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>400</width> |
||||
<height>300</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Cookies management</string> |
||||
</property> |
||||
<layout class="QGridLayout" name="gridLayout"> |
||||
<item row="0" column="0"> |
||||
<widget class="QTableWidget" name="cookiesTable"> |
||||
<property name="alternatingRowColors"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<property name="selectionMode"> |
||||
<enum>QAbstractItemView::SingleSelection</enum> |
||||
</property> |
||||
<attribute name="horizontalHeaderStretchLastSection"> |
||||
<bool>true</bool> |
||||
</attribute> |
||||
<attribute name="verticalHeaderVisible"> |
||||
<bool>false</bool> |
||||
</attribute> |
||||
<attribute name="verticalHeaderStretchLastSection"> |
||||
<bool>false</bool> |
||||
</attribute> |
||||
<column> |
||||
<property name="text"> |
||||
<string extracomment="As in Key/Value pair">Key</string> |
||||
</property> |
||||
</column> |
||||
<column> |
||||
<property name="text"> |
||||
<string extracomment="As in Key/Value pair">Value</string> |
||||
</property> |
||||
</column> |
||||
</widget> |
||||
</item> |
||||
<item row="0" column="1"> |
||||
<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="add_btn"> |
||||
<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="del_btn"> |
||||
<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> |
||||
<item row="2" column="0" colspan="2"> |
||||
<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> |
||||
<item row="1" column="0"> |
||||
<widget class="QLabel" name="infos_lbl"> |
||||
<property name="text"> |
||||
<string notr="true">TextLabel</string> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>accepted()</signal> |
||||
<receiver>CookiesDlg</receiver> |
||||
<slot>accept()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>248</x> |
||||
<y>254</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>157</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
<connection> |
||||
<sender>buttonBox</sender> |
||||
<signal>rejected()</signal> |
||||
<receiver>CookiesDlg</receiver> |
||||
<slot>reject()</slot> |
||||
<hints> |
||||
<hint type="sourcelabel"> |
||||
<x>316</x> |
||||
<y>260</y> |
||||
</hint> |
||||
<hint type="destinationlabel"> |
||||
<x>286</x> |
||||
<y>274</y> |
||||
</hint> |
||||
</hints> |
||||
</connection> |
||||
</connections> |
||||
</ui> |
Loading…
Reference in new issue