summaryrefslogtreecommitdiffstats
path: root/opensuse/core/tdelibs/textcompletion-editor.diff
blob: d147761492a6f0008ec39c01eb26287be3452431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
Index: khtml/khtmlview.h
===================================================================
--- khtml/khtmlview.h.orig
+++ khtml/khtmlview.h
@@ -314,6 +314,7 @@ private:
     QStringList formCompletionItems(const QString &name) const;
     void clearCompletionHistory(const QString& name);
     void addFormCompletionItem(const QString &name, const QString &value);
+    void removeFormCompletionItem(const QString &name, const QString &value);
 
     void addNonPasswordStorableSite( const QString& host );
     bool nonPasswordStorableSite( const QString& host ) const;
Index: khtml/khtmlview.cpp
===================================================================
--- khtml/khtmlview.cpp.orig
+++ khtml/khtmlview.cpp
@@ -3088,6 +3088,16 @@ void KHTMLView::addFormCompletionItem(co
     d->formCompletions->writeEntry(name, items);
 }
 
+void KHTMLView::removeFormCompletionItem(const QString &name, const QString &value)
+{
+    if (!m_part->settings()->isFormCompletionEnabled())
+        return;
+
+    QStringList items = formCompletionItems(name);
+    if (items.remove(value))
+        d->formCompletions->writeEntry(name, items);
+}
+
 void KHTMLView::addNonPasswordStorableSite(const QString& host)
 {
     if (!d->formCompletions) {
Index: khtml/rendering/render_form.h
===================================================================
--- khtml/rendering/render_form.h.orig
+++ khtml/rendering/render_form.h
@@ -272,10 +272,12 @@ private slots:
     void spellCheckerMisspelling( const QString &text, const QStringList &, unsigned int pos);
     void spellCheckerCorrected( const QString &, const QString &, unsigned int );
     void spellCheckerFinished();
+    void slotRemoveFromHistory( const QString & );
 
 private:
     enum LineEditMenuID {
-        ClearHistory
+        ClearHistory,
+        EditHistory
     };
     DOM::HTMLInputElementImpl* m_input;
     KHTMLView* m_view;
Index: khtml/rendering/render_form.cpp
===================================================================
--- khtml/rendering/render_form.cpp.orig
+++ khtml/rendering/render_form.cpp
@@ -385,7 +385,9 @@ QPopupMenu *LineEditWidget::createPopupM
 
     if (m_input->autoComplete()) {
         popup->insertSeparator();
-        int id = popup->insertItem( SmallIconSet("history_clear"), i18n("Clear &History"), ClearHistory );
+        int id = popup->insertItem( SmallIconSet("edit"), i18n("&Edit History..."), EditHistory );
+        popup->setItemEnabled( id, (compObj() && !compObj()->isEmpty()) );
+        id = popup->insertItem( SmallIconSet("history_clear"), i18n("Clear &History"), ClearHistory );
         popup->setItemEnabled( id, (compObj() && !compObj()->isEmpty()) );
     }
 
@@ -409,11 +411,25 @@ void LineEditWidget::extendedMenuActivat
         m_view->clearCompletionHistory(m_input->name().string());
         if (compObj())
           compObj()->clear();
+    case EditHistory:
+      {
+        KHistoryComboEditor dlg( compObj() ? compObj()->items() : QStringList(), this );
+        connect( &dlg, SIGNAL( removeFromHistory(const QString&) ), SLOT( slotRemoveFromHistory(const QString&)) );
+        dlg.exec();
+      }
     default:
         break;
     }
 }
 
+void LineEditWidget::slotRemoveFromHistory(const QString &entry)
+{
+    m_view->removeFormCompletionItem(m_input->name().string(), entry);
+    if (compObj())
+       compObj()->removeItem(entry);
+}
+
+
 bool LineEditWidget::event( QEvent *e )
 {
     if (KLineEdit::event(e))
Index: kdeui/kcombobox.h
===================================================================
--- kdeui/kcombobox.h.orig
+++ kdeui/kcombobox.h
@@ -24,8 +24,15 @@
 
 #include <qlineedit.h>
 #include <qcombobox.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qtoolbutton.h>
+#include <qheader.h>
 
 #include <kcompletion.h>
+#include <kdialogbase.h>
+#include <klistview.h>
 
 class QListBoxItem;
 class QPopupMenu;
@@ -669,6 +676,12 @@ public:
      */
     void reset() { slotReset(); }
 
+    /**
+     * When enabling it you have to connect to "removed" signal and save changes
+    */
+    void setHistoryEditorEnabled( bool enable );
+    bool isHistoryEditorEnabled() const;
+
 public slots:
     /**
      * Adds an item to the end of the history list and to the completion list.
@@ -702,6 +715,8 @@ signals:
      */
     void cleared();
 
+    void removed( const QString& item );
+
 protected:
     /**
      * Handling key-events, the shortcuts to rotate the items.
@@ -741,10 +756,17 @@ private slots:
     void slotClear();
 
     /**
+     * Called from the popupmenu,
+     */
+    void slotEdit();
+
+    /**
      * Appends our own context menu entry.
      */
     void addContextMenuItems( QPopupMenu* );
 
+    void slotRemoveFromHistory( const QString & );
+
 private:
     void init( bool useCompletion );
     void rotateUp();
@@ -774,6 +796,30 @@ private:
     KHistoryComboPrivate* const d;
 };
 
+class KDEUI_EXPORT KHistoryComboEditor : public KDialogBase
+{
+    Q_OBJECT
+
+public:
+    KHistoryComboEditor( const QStringList& entries, QWidget *parent = 0L );
+    ~KHistoryComboEditor();
+
+signals:
+    void removeFromHistory( const QString& );
+
+protected slots:
+    virtual void slotUser1(); // User1 is "Delete Entry" button
+    void slotSelectionChanged( QListViewItem * item );
+
+protected:
+    virtual void virtual_hook( int id, void* data );
+
+private:
+    KListView *m_pListView;
+
+    class KHistoryComboEditorPrivate;
+    KHistoryComboEditorPrivate* const d;
+};
 
 #endif
 
Index: kdeui/kcombobox.cpp
===================================================================
--- kdeui/kcombobox.cpp.orig
+++ kdeui/kcombobox.cpp
@@ -29,6 +29,7 @@
 #include <kcursor.h>
 #include <kiconloader.h>
 #include <kicontheme.h>
+#include <klistviewsearchline.h>
 #include <klineedit.h>
 #include <klocale.h>
 #include <knotifyclient.h>
@@ -343,10 +344,22 @@ void KComboBox::lineEditDeleted()
 // *********************************************************************
 // *********************************************************************
 
+class KHistoryCombo::KHistoryComboPrivate
+{
+public:
+    KHistoryComboPrivate() : bHistoryEditorEnabled(false)
+    {
+    }
+    ~KHistoryComboPrivate()
+    {
+    }
+
+    bool bHistoryEditorEnabled;
+};
 
 // we are always read-write
 KHistoryCombo::KHistoryCombo( QWidget *parent, const char *name )
-    : KComboBox( true, parent, name ), d(0)
+    : KComboBox( true, parent, name ), d(new KHistoryComboPrivate)
 {
     init( true ); // using completion
 }
@@ -354,7 +367,7 @@ KHistoryCombo::KHistoryCombo( QWidget *p
 // we are always read-write
 KHistoryCombo::KHistoryCombo( bool useCompletion,
                               QWidget *parent, const char *name )
-    : KComboBox( true, parent, name ), d(0)
+    : KComboBox( true, parent, name ), d(new KHistoryComboPrivate)
 {
     init( useCompletion );
 }
@@ -441,6 +454,10 @@ void KHistoryCombo::addContextMenuItems(
     if ( menu )
     {
         menu->insertSeparator();
+        if (d->bHistoryEditorEnabled) {
+           int idedit = menu->insertItem( SmallIconSet("edit"), i18n("&Edit History..."), this, SLOT( slotEdit()) );
+           menu->setItemEnabled(idedit, count());
+        }
         int id = menu->insertItem( SmallIconSet("history_clear"), i18n("Clear &History"), this, SLOT( slotClear()));
         if (!count())
            menu->setItemEnabled(id, false);
@@ -677,10 +694,104 @@ void KHistoryCombo::slotClear()
     emit cleared();
 }
 
+void KHistoryCombo::slotEdit()
+{
+    KHistoryComboEditor dlg( historyItems(), this );
+    connect( &dlg, SIGNAL( removeFromHistory(const QString&) ), SLOT( slotRemoveFromHistory(const QString&)) );
+    dlg.exec();
+}
+
+void KHistoryCombo::slotRemoveFromHistory(const QString &entry)
+{
+    removeFromHistory(entry);
+    emit removed(entry);
+}
+
+void KHistoryCombo::setHistoryEditorEnabled( bool enable )
+{
+    d->bHistoryEditorEnabled = enable;
+}
+
+bool KHistoryCombo::isHistoryEditorEnabled() const
+{
+    return d->bHistoryEditorEnabled;
+}
+
 void KComboBox::virtual_hook( int id, void* data )
 { KCompletionBase::virtual_hook( id, data ); }
 
 void KHistoryCombo::virtual_hook( int id, void* data )
 { KComboBox::virtual_hook( id, data ); }
 
+void KHistoryComboEditor::virtual_hook( int id, void* data )
+{ KDialogBase::virtual_hook( id, data ); }
+
+KHistoryComboEditor::KHistoryComboEditor( const QStringList& entries, QWidget *parent )
+: KDialogBase( parent, "khistorycomboeditor", true, i18n( "History Editor" ),
+    KDialogBase::Close | KDialogBase::User1, KDialogBase::User1, true,
+    KGuiItem( i18n( "&Delete Entry" ), "editdelete") ), d(0)
+{
+    QVBox* box = new QVBox( this );
+    box->setSpacing( KDialog::spacingHint() );
+    setMainWidget( box );
+
+    new QLabel( i18n( "This dialog allows you to delete unwanted history items." ), box );
+
+    // Add searchline
+    QHBox* searchbox = new QHBox( box );
+    searchbox->setSpacing( KDialog::spacingHint() );
+
+    QToolButton *clearSearch = new QToolButton(searchbox);
+    clearSearch->setTextLabel(i18n("Clear Search"), true);
+    clearSearch->setIconSet(SmallIconSet(QApplication::reverseLayout() ? "clear_left" : "locationbar_erase"));
+    QLabel* slbl = new QLabel(i18n("&Search:"), searchbox);
+    KListViewSearchLine* listViewSearch = new KListViewSearchLine(searchbox);
+    slbl->setBuddy(listViewSearch);
+    connect(clearSearch, SIGNAL(pressed()), listViewSearch, SLOT(clear()));
+
+    // Add ListView
+    m_pListView = new KListView( box );
+    listViewSearch->setListView(m_pListView);
+    m_pListView->setAllColumnsShowFocus(true);
+    m_pListView->header()->hide();
+    m_pListView->addColumn("");
+    m_pListView->setRenameable( 0 );
+
+    box->setStretchFactor( m_pListView, 1 );
+
+    QStringList newlist = entries;
+    for ( QStringList::Iterator it = newlist.begin(); it != newlist.end(); ++it ) {
+        new QListViewItem( m_pListView, *it );
+    }
+
+    m_pListView->setMinimumSize( m_pListView->sizeHint() );
+
+    connect( m_pListView, SIGNAL( selectionChanged( QListViewItem * ) ),
+             this, SLOT( slotSelectionChanged( QListViewItem * ) ) );
+
+    enableButton( KDialogBase::User1, false );
+
+    resize( sizeHint() );
+}
+
+KHistoryComboEditor::~KHistoryComboEditor()
+{
+}
+
+void KHistoryComboEditor::slotUser1() // Delete button
+{
+    QListViewItem *item = m_pListView->selectedItem();
+
+    if ( item ) {
+       emit removeFromHistory( item->text(0) );
+       m_pListView->takeItem( item );
+       enableButton( KDialogBase::User1, false );
+    }
+}
+
+void KHistoryComboEditor::slotSelectionChanged( QListViewItem * item )
+{
+    enableButton( KDialogBase::User1, item );
+}
+
 #include "kcombobox.moc"