• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • ui
  • metalinkcreator
urlwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "urlwidget.h"
21 #include "metalinker.h"
22 #include "../mirror/mirrormodel.h"
23 #include "../mirror/mirrorsettings.h"
24 
25 #include <QtGui/QSortFilterProxyModel>
26 
27 UrlWidget::UrlWidget(QObject *parent)
28  : QObject(parent),
29  m_resources(0),
30  m_countrySort(0),
31  m_widget(0)
32 {
33  m_widget = new QWidget;//TODO inherit from qWidget and set this widget as mainwidget?
34  ui.setupUi(m_widget);
35 
36  m_mirrorModel = new MirrorModel(this);
37  m_proxy = new MirrorProxyModel(this);
38  m_proxy->setSourceModel(m_mirrorModel);
39  ui.used_mirrors->setModel(m_proxy);
40  ui.used_mirrors->sortByColumn(MirrorItem::Priority, Qt::DescendingOrder);
41  ui.used_mirrors->resizeColumnToContents(MirrorItem::Priority);
42  ui.used_mirrors->hideColumn(MirrorItem::Used);
43  ui.used_mirrors->hideColumn(MirrorItem::Connections);
44 
45  ui.add_mirror->setGuiItem(KStandardGuiItem::add());
46  ui.remove_mirror->setGuiItem(KStandardGuiItem::remove());
47  ui.remove_mirror->setEnabled(false);
48  connect(ui.used_mirrors->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUrlClicked()));
49  connect(ui.add_mirror, SIGNAL(clicked(bool)), this, SLOT(slotAddMirror()));
50  connect(ui.remove_mirror, SIGNAL(clicked(bool)), this, SLOT(slotRemoveMirror()));
51  connect(m_mirrorModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(urlsChanged()));
52  connect(m_mirrorModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(urlsChanged()));
53  connect(m_mirrorModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(urlsChanged()));
54 }
55 
56 UrlWidget::~UrlWidget()
57 {
58  delete m_widget;
59 }
60 
61 QWidget *UrlWidget::widget()
62 {
63  return m_widget;
64 }
65 
66 void UrlWidget::init(KGetMetalink::Resources *resources, QSortFilterProxyModel *countrySort)
67 {
68  if (m_resources)
69  {
70  m_mirrorModel->removeRows(0, m_mirrorModel->rowCount());
71  }
72 
73  m_resources = resources;
74  m_countrySort = countrySort;
75 
76  foreach (const KGetMetalink::Url &url, m_resources->urls)
77  {
78  m_mirrorModel->addMirror(url.url, 0, url.priority, url.location);
79  }
80 
81  MirrorDelegate *delegate = new MirrorDelegate(m_countrySort, this);
82  ui.used_mirrors->setItemDelegate(delegate);
83 }
84 
85 bool UrlWidget::hasUrls() const
86 {
87  return m_mirrorModel->rowCount();
88 }
89 
90 void UrlWidget::slotUrlClicked()
91 {
92  const QModelIndexList selected = ui.used_mirrors->selectionModel()->selectedRows();
93  ui.remove_mirror->setEnabled(!selected.isEmpty());
94 }
95 
96 void UrlWidget::slotAddMirror()
97 {
98  MirrorAddDlg *dialog = new MirrorAddDlg(m_mirrorModel, m_countrySort, m_widget);
99  dialog->showItem(MirrorItem::Connections, false);
100  dialog->show();
101 }
102 
103 void UrlWidget::slotRemoveMirror()
104 {
105  while (ui.used_mirrors->selectionModel()->hasSelection()) {
106  const QModelIndex index = ui.used_mirrors->selectionModel()->selectedRows().first();
107  m_mirrorModel->removeRow(m_proxy->mapToSource(index).row());
108  }
109 }
110 
111 void UrlWidget::save()
112 {
113  if (m_resources)
114  {
115  for (int i = 0; i < m_mirrorModel->rowCount(); ++i)
116  {
117  KGetMetalink::Url url;
118  url.url = KUrl(m_mirrorModel->index(i, MirrorItem::Url).data(Qt::UserRole).toUrl());
119  url.priority = m_mirrorModel->index(i, MirrorItem::Priority).data(Qt::UserRole).toInt();
120  url.location = m_mirrorModel->index(i, MirrorItem::Country).data(Qt::UserRole).toString();
121  m_resources->urls.append(url);
122  }
123  }
124 }
125 
126 
127 #include "urlwidget.moc"
MirrorItem::Connections
Definition: mirrormodel.h:69
UrlWidget::urlsChanged
void urlsChanged()
KGetMetalink::Url
Definition: metalinker.h:156
UrlWidget::widget
QWidget * widget()
Definition: urlwidget.cpp:61
QWidget
MirrorItem::Url
Definition: mirrormodel.h:68
QObject
MirrorDelegate
Definition: mirrormodel.h:31
MirrorModel::addMirror
void addMirror(const KUrl &url, int numConnections=0, int priority=0, const QString &countryCode=QString())
Definition: mirrormodel.cpp:456
MirrorModel
Definition: mirrormodel.h:88
KGetMetalink::Url::priority
uint priority
the priority of the urls, 1 is highest priority, 999999 lowest default is 0 as in not set and thus is...
Definition: metalinker.h:180
KGetMetalink::Url::location
QString location
the location of the server eg.
Definition: metalinker.h:185
MirrorProxyModel
Definition: mirrormodel.h:49
MirrorItem::Priority
Definition: mirrormodel.h:70
UrlWidget::~UrlWidget
~UrlWidget()
Definition: urlwidget.cpp:56
MirrorItem::Used
Definition: mirrormodel.h:67
metalinker.h
KGetMetalink::Resources::urls
QList< Url > urls
Definition: metalinker.h:202
KGetMetalink::Url::url
KUrl url
Definition: metalinker.h:187
MirrorAddDlg::showItem
void showItem(MirrorItem::DataType type, bool show)
Shows or hides elements, by default all (expect MirrorItem::Used) are shown.
Definition: mirrorsettings.cpp:72
MirrorModel::removeRows
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
Definition: mirrormodel.cpp:436
MirrorModel::rowCount
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition: mirrormodel.cpp:359
MirrorAddDlg
Definition: mirrorsettings.h:32
QSortFilterProxyModel
urlwidget.h
UrlWidget::save
void save()
Definition: urlwidget.cpp:111
MirrorModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: mirrormodel.cpp:404
UrlWidget::init
void init(KGetMetalink::Resources *resources, QSortFilterProxyModel *countrySort)
Definition: urlwidget.cpp:66
KGetMetalink::Resources
Definition: metalinker.h:190
UrlWidget::UrlWidget
UrlWidget(QObject *parent=0)
Definition: urlwidget.cpp:27
UrlWidget::hasUrls
bool hasUrls() const
Definition: urlwidget.cpp:85
MirrorItem::Country
Definition: mirrormodel.h:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal