• 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
  • conf
integrationpreferences.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2010 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 "integrationpreferences.h"
21 #include "autopastemodel.h"
22 #include "settings.h"
23 
24 #include <KConfigDialog>
25 
26 IntegrationPreferences::IntegrationPreferences(KConfigDialog *parent, Qt::WindowFlags f)
27  : QWidget(parent, f)
28 {
29  ui.setupUi(this);
30 
31  //AutoPaste stuff
32  ui.type->addItem(KIcon("list-add"), i18n("Include"), AutoPasteModel::Include);
33  ui.type->addItem(KIcon("list-remove"), i18n("Exclude"), AutoPasteModel::Exclude);
34 
35  ui.patternSyntax->addItem(i18n("Escape sequences"), AutoPasteModel::Wildcard);
36  ui.patternSyntax->addItem(i18n("Regular expression"), AutoPasteModel::RegExp);
37 
38  ui.add->setGuiItem(KStandardGuiItem::add());
39  ui.remove->setGuiItem(KStandardGuiItem::remove());
40  ui.increase->setIcon(KIcon("arrow-up"));
41  ui.decrease->setIcon(KIcon("arrow-down"));
42 
43  m_model = new AutoPasteModel(this);
44  m_model->load();
45  ui.list->setModel(m_model);
46  AutoPasteDelegate *delegate = new AutoPasteDelegate(ui.type->model(), ui.patternSyntax->model(), this);
47  ui.list->setItemDelegate(delegate);
48 
49  QByteArray loadedState = QByteArray::fromBase64(Settings::autoPasteHeaderState().toAscii());
50  if (Settings::autoPasteHeaderState().isEmpty()) {
51  ui.list->resizeColumnToContents(AutoPasteModel::Type);
52  } else if (!loadedState.isNull()) {
53  ui.list->header()->restoreState(loadedState);
54  }
55 
56  connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(changed()));
57  connect(ui.list->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotUpdateButtons()));
58  connect(ui.pattern, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateButtons()));
59  connect(ui.pattern, SIGNAL(returnPressed(QString)), this, SLOT(slotAddItem()));
60  connect(ui.add, SIGNAL(clicked()), this, SLOT(slotAddItem()));
61  connect(ui.remove, SIGNAL(clicked()), this, SLOT(slotRemoveItem()));
62  connect(ui.increase, SIGNAL(clicked()), this, SLOT(slotIncreasePriority()));
63  connect(ui.decrease, SIGNAL(clicked()), this, SLOT(slotDecreasePriority()));
64  connect(parent, SIGNAL(rejected()), m_model, SLOT(load()));
65  connect(parent, SIGNAL(applyClicked()), m_model, SLOT(save()));
66  connect(parent, SIGNAL(okClicked()), m_model, SLOT(save()));
67  connect(parent, SIGNAL(defaultClicked()), m_model, SLOT(resetDefaults()));
68 
69  slotUpdateButtons();
70 }
71 
72 IntegrationPreferences::~IntegrationPreferences()
73 {
74 }
75 
76 void IntegrationPreferences::slotUpdateButtons()
77 {
78  ui.add->setEnabled(!ui.pattern->text().isEmpty());
79  ui.remove->setEnabled(ui.list->selectionModel()->hasSelection());
80 
81  const QModelIndex index = ui.list->currentIndex();
82  const bool indexValid = index.isValid() && (ui.list->selectionModel()->selectedRows().count() == 1);
83  ui.increase->setEnabled(indexValid && (index.row() > 0));
84  ui.decrease->setEnabled(indexValid && (m_model->rowCount() > (index.row() + 1)));
85 }
86 
87 void IntegrationPreferences::slotAddItem()
88 {
89  const QString pattern = ui.pattern->text();
90  if (pattern.isEmpty()) {
91  return;
92  }
93 
94  AutoPasteModel::TypeData type = static_cast<AutoPasteModel::TypeData>(ui.type->itemData(ui.type->currentIndex()).toInt());
95  AutoPasteModel::PatternSyntaxData syntax = static_cast<AutoPasteModel::PatternSyntaxData>(ui.patternSyntax->itemData(ui.patternSyntax->currentIndex()).toInt());
96  m_model->addItem(type, syntax, pattern);
97 
98  ui.pattern->clear();
99  ui.pattern->setFocus();
100  emit changed();
101 }
102 
103 void IntegrationPreferences::slotRemoveItem()
104 {
105  QItemSelectionModel *selection = ui.list->selectionModel();
106  if (selection->hasSelection()) {
107  while (selection->selectedRows().count()) {
108  const QModelIndex index = selection->selectedRows().first();
109  m_model->removeRow(index.row());
110  }
111  emit changed();
112  }
113 }
114 
115 void IntegrationPreferences::slotIncreasePriority()
116 {
117  const int row = ui.list->currentIndex().row();
118  m_model->moveItem(row, row - 1);
119  slotUpdateButtons();
120  emit changed();
121 }
122 
123 void IntegrationPreferences::slotDecreasePriority()
124 {
125  const int row = ui.list->currentIndex().row();
126  m_model->moveItem(row, row + 2);
127  slotUpdateButtons();
128  emit changed();
129 }
130 
QItemSelectionModel
AutoPasteModel
Definition: autopastemodel.h:44
AutoPasteModel::PatternSyntaxData
PatternSyntaxData
Definition: autopastemodel.h:58
AutoPasteModel::rowCount
int rowCount(const QModelIndex &index=QModelIndex()) const
Definition: autopastemodel.cpp:148
QWidget
AutoPasteModel::RegExp
Definition: autopastemodel.h:60
AutoPasteModel::TypeData
TypeData
Definition: autopastemodel.h:54
AutoPasteModel::Include
Definition: autopastemodel.h:55
KConfigDialog
AutoPasteModel::Wildcard
Definition: autopastemodel.h:59
integrationpreferences.h
AutoPasteModel::load
void load()
Loads the stored data.
Definition: autopastemodel.cpp:313
AutoPasteDelegate
Definition: autopastemodel.h:26
AutoPasteModel::Type
Definition: autopastemodel.h:50
settings.h
IntegrationPreferences::changed
void changed()
Emitted whenever something changes.
AutoPasteModel::moveItem
bool moveItem(int sourceRow, int destinationRow)
Moves an item to a new position.
Definition: autopastemodel.cpp:297
autopastemodel.h
AutoPasteModel::addItem
void addItem(TypeData dataType, PatternSyntaxData patternSyntax, const QString &pattern)
Adds an an item.
Definition: autopastemodel.cpp:275
IntegrationPreferences::IntegrationPreferences
IntegrationPreferences(KConfigDialog *parent, Qt::WindowFlags f=0)
Definition: integrationpreferences.cpp:26
AutoPasteModel::Exclude
Definition: autopastemodel.h:56
IntegrationPreferences::~IntegrationPreferences
~IntegrationPreferences()
Definition: integrationpreferences.cpp:72
Settings::autoPasteHeaderState
static QString autoPasteHeaderState()
Get AutoPasteHeaderState.
Definition: settings.h:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 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