~ubuntu-branches/ubuntu/karmic/kchmviewer/karmic

« back to all changes in this revision

Viewing changes to src/kchmbookmarkwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-07-29 21:43:18 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090729214318-590zmgax0swvqbny
Tags: 4.1-1
* New upstream release. (Closes: #479402, #496888)
* Add patch to disable kio-msits build to avoid okular-extra-backends
  conflict.
* Bump compat/debhelper to 7.
* Update debian/control:
  - Set Debian KDE Extras Team as Maintainer and myself in Uploaders.
  - Update build dependencies:
    - Add cmake, quilt and pkg-kde-tools
    - Replace kdelibs4-dev by kdelibs5-dev
    - Remove autotools-dev
  - Update Standards-Version to 3.8.2 (no changes needed).
  - Add Homepage field
* Remove deprecated files: debiandirs, dirs and Makefile.
* Update debian/menu file to Debian menu policy 2.1
* Switch debian/rules to dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                                                                         *
6
6
 *   This program is free software; you can redistribute it and/or modify  *
7
7
 *   it under the terms of the GNU General Public License as published by  *
8
 
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   the Free Software Foundation; either version 3 of the License, or     *
9
9
 *   (at your option) any later version.                                   *
10
10
 *                                                                         *
11
11
 *   This program is distributed in the hope that it will be useful,       *
16
16
 *   You should have received a copy of the GNU General Public License     *
17
17
 *   along with this program; if not, write to the                         *
18
18
 *   Free Software Foundation, Inc.,                                       *
19
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
20
20
 ***************************************************************************/
21
21
 
22
22
#include "kchmbookmarkwindow.h"
23
23
#include "kchmmainwindow.h"
24
24
#include "kchmviewwindow.h"
25
 
#include "kchmlistitemtooltip.h"
26
25
#include "kchmtreeviewitem.h"
27
 
 
28
 
#include "kchmbookmarkwindow.moc"
29
 
 
30
 
KCHMBookmarkWindow::KCHMBookmarkWindow(QWidget *parent, const char *name)
31
 
 : QWidget(parent, name)
32
 
{
33
 
        QVBoxLayout * layout = new QVBoxLayout (this);
34
 
        layout->setMargin (5);
35
 
 
36
 
        m_bookmarkList = new KQListView (this);
37
 
        m_bookmarkList->addColumn( "bookmark" ); // no need to i18n - the column is hidden
38
 
        m_bookmarkList->header()->hide();
39
 
        layout->addWidget (m_bookmarkList);
40
 
 
41
 
        new KCHMListItemTooltip( m_bookmarkList );
42
 
        
43
 
        QHBoxLayout * hlayout = new QHBoxLayout (layout);
44
 
        QPushButton * add = new QPushButton ( i18n( "&Add" ), this);
45
 
        QPushButton * edit = new QPushButton ( i18n( "&Edit" ), this);
46
 
        QPushButton * del = new QPushButton ( i18n( "&Del" ), this);
47
 
        
48
 
        hlayout->addWidget (add);
49
 
        hlayout->addWidget (edit);
50
 
        hlayout->addWidget (del);
51
 
        
52
 
        connect( m_bookmarkList, 
53
 
                         SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int) ), 
 
26
#include "version.h"
 
27
 
 
28
class KCHMBookmarkItem : public QListWidgetItem
 
29
{
 
30
        public:
 
31
                KCHMBookmarkItem( KCHMBookmarkWindow * widget, QListWidget* parent, const QString& name, const QString& url, int pos )
 
32
                        : QListWidgetItem( parent )
 
33
                {
 
34
                        m_name = name;
 
35
                        m_url = url;
 
36
                        m_scroll_y = pos;
 
37
                        m_action = new QAction( name, widget );
 
38
                        m_action->setData( qVariantFromValue( (void*) this ) );
 
39
                        
 
40
                        QObject::connect( m_action,
 
41
                                 SIGNAL( triggered() ),
 
42
                                 widget,
 
43
                                 SLOT( actionBookmarkActivated() ) );
 
44
                }
 
45
        
 
46
                // Visualization
 
47
                virtual QVariant data ( int role ) const
 
48
                {
 
49
                        switch ( role )
 
50
                        {
 
51
                        case Qt::ToolTipRole:
 
52
                        case Qt::WhatsThisRole:
 
53
                        case Qt::DisplayRole:
 
54
                                return m_name;
 
55
                        }
 
56
                        
 
57
                        return QVariant();
 
58
                }
 
59
        
 
60
                QString         m_name;
 
61
                QString         m_url;
 
62
                int                     m_scroll_y;
 
63
                QAction *       m_action;
 
64
};
 
65
 
 
66
 
 
67
 
 
68
KCHMBookmarkWindow::KCHMBookmarkWindow( QWidget *parent )
 
69
        : QWidget( parent ), Ui::TabBookmarks()
 
70
{
 
71
        // UIC code
 
72
        setupUi( this );
 
73
        
 
74
        connect( list,
 
75
                         SIGNAL( itemDoubleClicked ( QListWidgetItem* ) ),
54
76
                         this, 
55
 
                         SLOT( onDoubleClicked ( QListViewItem *, const QPoint &, int) ) );
 
77
                 SLOT( onItemDoubleClicked ( QListWidgetItem* ) ) );
56
78
        
57
 
        connect( add, 
 
79
        connect( btnAdd, 
58
80
                         SIGNAL( clicked () ), 
59
81
                         this, 
60
82
                         SLOT( onAddBookmarkPressed( ) ) );
61
83
        
62
 
        connect( del, 
 
84
        connect( btnDel, 
63
85
                         SIGNAL( clicked () ), 
64
86
                         this, 
65
87
                         SLOT( onDelBookmarkPressed( ) ) );
66
88
        
67
 
        connect( edit, 
 
89
        connect( btnEdit, 
68
90
                         SIGNAL( clicked () ), 
69
91
                         this, 
70
92
                         SLOT( onEditBookmarkPressed( ) ) );
71
93
        
72
 
        connect( m_bookmarkList, 
73
 
                         SIGNAL( contextMenuRequested( QListViewItem *, const QPoint& , int ) ),
74
 
                         this, 
75
 
                         SLOT( slotContextMenuRequested ( QListViewItem *, const QPoint &, int ) ) );
76
 
 
77
94
        m_menuBookmarks = 0;
78
95
        m_contextMenu = 0;
79
96
        m_listChanged = false;
 
97
 
 
98
        // Activate custom context menu, and connect it
 
99
        list->setContextMenuPolicy( Qt::CustomContextMenu );
 
100
        connect( list, 
 
101
                 SIGNAL( customContextMenuRequested ( const QPoint & ) ),
 
102
                 this, 
 
103
                 SLOT( onContextMenuRequested( const QPoint & ) ) );
80
104
}
81
105
 
82
106
void KCHMBookmarkWindow::onAddBookmarkPressed( )
85
109
        QString url = ::mainWindow->currentBrowser()->getOpenedPage();
86
110
        QString title = ::mainWindow->chmFile()->getTopicByUrl(url);
87
111
        QString name = QInputDialog::getText( 
 
112
                this,
88
113
                        i18n( "%1 - add a bookmark") . arg(APP_NAME),
89
114
                        i18n( "Enter the name for this bookmark:" ),
90
115
                        QLineEdit::Normal,
91
116
                        title,
92
 
                        &ok, 
93
 
                        this);
 
117
                        &ok );
94
118
    
95
119
        if ( !ok || name.isEmpty() )
96
120
                return;
97
121
 
98
 
        KCHMBookmarkTreeViewItem * item = new KCHMBookmarkTreeViewItem (
99
 
                        m_bookmarkList, 
100
 
                        name, 
101
 
                        url, 
102
 
                        ::mainWindow->currentBrowser()->getScrollbarPosition() );
 
122
        KCHMBookmarkItem * item = new KCHMBookmarkItem ( this,
 
123
                                                         list, 
 
124
                                                         name, 
 
125
                                                         url, 
 
126
                                                         ::mainWindow->currentBrowser()->getScrollbarPosition() );
103
127
        
104
 
        item->menuid = m_menuBookmarks->insertItem( name );
 
128
        m_menuBookmarks->addAction( item->m_action );
105
129
        m_listChanged = true;
106
130
}
107
131
 
108
132
 
109
133
void KCHMBookmarkWindow::onDelBookmarkPressed( )
110
134
{
111
 
        KCHMBookmarkTreeViewItem * item = (KCHMBookmarkTreeViewItem *) m_bookmarkList->selectedItem();
 
135
        KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->currentItem();
112
136
        
113
137
        if ( item )
114
138
        {
115
 
                m_menuBookmarks->removeItem( item->menuid );
 
139
                m_menuBookmarks->removeAction( item->m_action );
116
140
                delete item;
117
141
                m_listChanged = true;
118
142
        }
121
145
 
122
146
void KCHMBookmarkWindow::onEditBookmarkPressed( )
123
147
{
124
 
        KCHMBookmarkTreeViewItem * item = (KCHMBookmarkTreeViewItem *) m_bookmarkList->selectedItem();
 
148
        KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->currentItem();
125
149
        
126
150
        if ( item )
127
151
        {
128
152
            bool ok;
129
153
                QString name = QInputDialog::getText( 
130
 
                        i18n( "%1 - edit the bookmark name") . arg(APP_NAME),
 
154
                        this,
 
155
                    i18n( "%1 - edit the bookmark name") . arg(APP_NAME),
131
156
                        i18n( "Enter the name for this bookmark:" ),
132
157
                        QLineEdit::Normal,
133
 
                        item->name, 
134
 
                        &ok, 
135
 
                        this);
 
158
                        item->m_name, 
 
159
                        &ok );
136
160
    
137
161
                if ( !ok || name.isEmpty() )
138
162
                        return;
139
163
 
140
 
                item->setText (0, name);
141
 
                m_menuBookmarks->changeItem( item->menuid, name );
 
164
                item->setText( name );
 
165
                item->m_action->setText( name );
142
166
                m_listChanged = true;
143
167
        }
144
168
}
145
169
 
146
170
 
147
 
void KCHMBookmarkWindow::onDoubleClicked( QListViewItem * item, const QPoint &, int )
148
 
{
149
 
        if ( !item )
150
 
                return;
151
 
        
152
 
        KCHMBookmarkTreeViewItem * treeitem = (KCHMBookmarkTreeViewItem *) item;
153
 
        
154
 
        if ( ::mainWindow->currentBrowser()->getOpenedPage() != treeitem->url )
155
 
                ::mainWindow->openPage( treeitem->url, OPF_CONTENT_TREE | OPF_ADD2HISTORY );
156
 
        
157
 
        ::mainWindow->currentBrowser()->setScrollbarPosition(treeitem->scroll_y);
158
 
}
159
 
 
160
 
 
161
171
void KCHMBookmarkWindow::restoreSettings( const KCHMSettings::bookmark_saved_settings_t & settings )
162
172
{
163
 
        for ( unsigned int i = 0; i < settings.size(); i++ )
 
173
        for ( int i = 0; i < settings.size(); i++ )
164
174
        {
165
 
                KCHMBookmarkTreeViewItem * item = new KCHMBookmarkTreeViewItem (m_bookmarkList, settings[i].name, settings[i].url, settings[i].scroll_y);
166
 
                
167
 
                item->menuid = m_menuBookmarks->insertItem( settings[i].name );
 
175
                KCHMBookmarkItem * item = new KCHMBookmarkItem( this, list, settings[i].name, settings[i].url, settings[i].scroll_y );
 
176
                m_menuBookmarks->addAction( item->m_action );
168
177
        }
169
178
}
170
179
 
171
180
 
172
181
void KCHMBookmarkWindow::saveSettings( KCHMSettings::bookmark_saved_settings_t & settings )
173
182
{
174
 
    QListViewItemIterator it (m_bookmarkList);
175
 
 
176
183
        settings.clear();
177
184
 
178
 
        for ( ; it.current(); it++ )
 
185
        for ( int i = 0; i < list->count(); i++ )
179
186
        {
180
 
                KCHMBookmarkTreeViewItem * treeitem = (KCHMBookmarkTreeViewItem *) it.current();
181
 
                settings.push_back (KCHMSettings::SavedBookmark(treeitem->name, treeitem->url, treeitem->scroll_y));
 
187
                KCHMBookmarkItem * treeitem = (KCHMBookmarkItem *) list->item( i );
 
188
                settings.push_back (KCHMSettings::SavedBookmark( treeitem->m_name, treeitem->m_url, treeitem->m_scroll_y) );
182
189
    }
183
190
}
184
191
 
185
192
void KCHMBookmarkWindow::invalidate( )
186
193
{
187
 
        QListViewItemIterator it( m_bookmarkList );
188
 
        
189
 
        for ( ; it.current(); it++ )
190
 
                m_menuBookmarks->removeItem( ((KCHMBookmarkTreeViewItem *) it.current())->menuid );
191
 
 
192
 
        m_bookmarkList->clear();
193
 
}
194
 
 
195
 
void KCHMBookmarkWindow::createMenu( KCHMMainWindow * parent )
196
 
{
197
 
        // Create the main Bookmark menu
198
 
        m_menuBookmarks = new KQPopupMenu( parent );
199
 
        parent->menuBar()->insertItem( i18n( "&Bookmarks"), m_menuBookmarks );
200
 
 
201
 
        m_menuBookmarks->insertItem( i18n( "&Add bookmark"), this, SLOT(onAddBookmarkPressed()), CTRL+Key_B );
202
 
        m_menuBookmarks->insertSeparator();
203
 
 
204
 
        connect( m_menuBookmarks, SIGNAL( activated(int) ), this, SLOT ( onBookmarkSelected(int) ));
205
 
}
206
 
 
207
 
void KCHMBookmarkWindow::onBookmarkSelected( int bookmark )
208
 
{
209
 
        QListViewItemIterator it( m_bookmarkList );
210
 
        
211
 
        for ( ; it.current(); it++ )
212
 
        {
213
 
                if ( ((KCHMBookmarkTreeViewItem *) it.current())->menuid == bookmark )
214
 
                {
215
 
                        KCHMBookmarkTreeViewItem * treeitem = (KCHMBookmarkTreeViewItem *) it.current();
216
 
        
217
 
                        if ( ::mainWindow->currentBrowser()->getOpenedPage() != treeitem->url )
218
 
                                ::mainWindow->openPage( treeitem->url, OPF_CONTENT_TREE | OPF_ADD2HISTORY );
219
 
        
220
 
                        ::mainWindow->currentBrowser()->setScrollbarPosition(treeitem->scroll_y);
221
 
                        break;
222
 
                }
223
 
        }
224
 
}
225
 
 
226
 
void KCHMBookmarkWindow::slotContextMenuRequested( QListViewItem * item, const QPoint & point, int )
227
 
{
228
 
        if ( !m_contextMenu )
229
 
                m_contextMenu = ::mainWindow->currentBrowser()->createListItemContextMenu( this );
230
 
                
 
194
        for ( int i = 0; i < list->count(); i++ )
 
195
                m_menuBookmarks->removeAction( ((KCHMBookmarkItem *) list->item( i ))->m_action );
 
196
 
 
197
        list->clear();
 
198
}
 
199
 
 
200
void KCHMBookmarkWindow::createMenu( QMenu * menuBookmarks )
 
201
{
 
202
        m_menuBookmarks = menuBookmarks;
 
203
}
 
204
 
 
205
void KCHMBookmarkWindow::onItemDoubleClicked(QListWidgetItem * item)
 
206
{
 
207
        if ( !item )
 
208
                return;
 
209
        
 
210
        KCHMBookmarkItem * treeitem = (KCHMBookmarkItem *) item;
 
211
        
 
212
        if ( ::mainWindow->currentBrowser()->getOpenedPage() != treeitem->m_url )
 
213
                ::mainWindow->openPage( treeitem->m_url, KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY );
 
214
        
 
215
        ::mainWindow->currentBrowser()->setScrollbarPosition( treeitem->m_scroll_y );
 
216
}
 
217
 
 
218
void KCHMBookmarkWindow::actionBookmarkActivated()
 
219
{
 
220
        QAction *action = qobject_cast< QAction * >(sender());
 
221
 
 
222
        KCHMBookmarkItem * item = (KCHMBookmarkItem *) action->data().value< void* > ();
 
223
        
 
224
        if ( !item )
 
225
                return;
 
226
        
 
227
        if ( ::mainWindow->currentBrowser()->getOpenedPage() != item->m_url )
 
228
                ::mainWindow->openPage( item->m_url, KCHMMainWindow::OPF_CONTENT_TREE | KCHMMainWindow::OPF_ADD2HISTORY );
 
229
        
 
230
        ::mainWindow->currentBrowser()->setScrollbarPosition( item->m_scroll_y );
 
231
}
 
232
 
 
233
void KCHMBookmarkWindow::onContextMenuRequested(const QPoint & point)
 
234
{
 
235
        KCHMBookmarkItem * item = (KCHMBookmarkItem *) list->itemAt( point );
 
236
        
231
237
        if( item )
232
238
        {
233
 
                KCHMBookmarkTreeViewItem * treeitem = (KCHMBookmarkTreeViewItem *) item;
234
 
                
235
 
                ::mainWindow->currentBrowser()->setTabKeeper( treeitem->url );
236
 
                m_contextMenu->popup( point );
 
239
                ::mainWindow->currentBrowser()->setTabKeeper( item->m_url );
 
240
                ::mainWindow->tabItemsContextMenu()->popup( list->viewport()->mapToGlobal( point ) );
237
241
        }
238
242
}
239