summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opierec/helpwindow.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opierec/helpwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opierec/helpwindow.cpp219
1 files changed, 219 insertions, 0 deletions
diff --git a/noncore/multimedia/opierec/helpwindow.cpp b/noncore/multimedia/opierec/helpwindow.cpp
new file mode 100644
index 0000000..0c4ac78
--- a/dev/null
+++ b/noncore/multimedia/opierec/helpwindow.cpp
@@ -0,0 +1,219 @@
1/****************************************************************************
2** $Id$
3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include "helpwindow.h"
12#include <qstatusbar.h>
13#include <qstringlist.h>
14#include <qlayout.h>
15
16#include <qpe/qpemenubar.h>
17#include <qpe/qpetoolbar.h>
18#include <qpe/resource.h>
19
20#include <qaction.h>
21#include <qpixmap.h>
22#include <qpopupmenu.h>
23#include <qmenubar.h>
24#include <qtoolbutton.h>
25#include <qiconset.h>
26#include <qfile.h>
27#include <qtextstream.h>
28#include <qstylesheet.h>
29#include <qmessagebox.h>
30#include <qfiledialog.h>
31#include <qapplication.h>
32#include <qcombobox.h>
33#include <qevent.h>
34#include <qlineedit.h>
35#include <qobjectlist.h>
36#include <qfileinfo.h>
37#include <qfile.h>
38#include <qdatastream.h>
39#include <qprinter.h>
40#include <qsimplerichtext.h>
41#include <qpaintdevicemetrics.h>
42
43#include <ctype.h>
44
45HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name )
46 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL()
47{
48 QGridLayout *layout = new QGridLayout( this );
49 layout->setSpacing( 2);
50 layout->setMargin( 2);
51 qDebug(_path);
52 browser = new QTextBrowser( this );
53 QStringList Strlist;
54 Strlist.append( home_);
55 browser->mimeSourceFactory()->setFilePath( Strlist );
56 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
57
58 connect( browser, SIGNAL( textChanged() ), this, SLOT( textChanged() ) );
59
60 if ( !home_.isEmpty() )
61 browser->setSource( home_ );
62 QPEToolBar *toolbar = new QPEToolBar( this );
63
64 QAction *a = new QAction( tr( "Backward" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
65 connect( a, SIGNAL( activated() ), browser, SLOT( backward() ) );
66 a->addTo( toolbar );
67
68 a = new QAction( tr( "Forward" ), Resource::loadPixmap( "forward" ), QString::null, 0, this, 0 );
69 connect( a, SIGNAL( activated() ), browser, SLOT( forward() ) );
70 a->addTo( toolbar );
71
72
73 layout->addMultiCellWidget( toolbar, 0, 0, 0, 0);
74
75 layout->addMultiCellWidget( browser, 1, 2, 0, 2);
76
77 browser->setFocus();
78}
79
80
81void HelpWindow::setBackwardAvailable( bool b)
82{
83 menuBar()->setItemEnabled( backwardId, b);
84}
85
86void HelpWindow::setForwardAvailable( bool b)
87{
88 menuBar()->setItemEnabled( forwardId, b);
89}
90
91
92void HelpWindow::textChanged()
93{
94 if ( browser->documentTitle().isNull() ) {
95 setCaption( "QpeRec - Helpviewer - " + browser->context() );
96 selectedURL = browser->context();
97 }
98 else {
99 setCaption( "QpeRec - Helpviewer - " + browser->documentTitle() ) ;
100 selectedURL = browser->documentTitle();
101 }
102
103// if ( !selectedURL.isEmpty() && pathCombo ) {
104// bool exists = FALSE;
105// int i;
106// for ( i = 0; i < pathCombo->count(); ++i ) {
107// if ( pathCombo->text( i ) == selectedURL ) {
108// exists = TRUE;
109// break;
110// }
111// }
112// if ( !exists ) {
113// pathCombo->insertItem( selectedURL, 0 );
114// pathCombo->setCurrentItem( 0 );
115// mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
116// } else
117// pathCombo->setCurrentItem( i );
118// selectedURL = QString::null;
119// }
120}
121
122HelpWindow::~HelpWindow()
123{
124 history.clear();
125 QMap<int, QString>::Iterator it = mHistory.begin();
126 for ( ; it != mHistory.end(); ++it )
127 history.append( *it );
128
129 QFile f( QDir::currentDirPath() + "/.history" );
130 f.open( IO_WriteOnly );
131 QDataStream s( &f );
132 s << history;
133 f.close();
134
135 bookmarks.clear();
136 QMap<int, QString>::Iterator it2 = mBookmarks.begin();
137 for ( ; it2 != mBookmarks.end(); ++it2 )
138 bookmarks.append( *it2 );
139
140 QFile f2( QDir::currentDirPath() + "/.bookmarks" );
141 f2.open( IO_WriteOnly );
142 QDataStream s2( &f2 );
143 s2 << bookmarks;
144 f2.close();
145}
146
147void HelpWindow::openFile()
148{
149#ifndef QT_NO_FILEDIALOG
150#endif
151}
152
153void HelpWindow::newWindow()
154{
155 ( new HelpWindow(browser->source(), "qbrowser") )->show();
156}
157
158void HelpWindow::print()
159{
160#ifndef QT_NO_PRINTER
161#endif
162}
163
164void HelpWindow::pathSelected( const QString &_path )
165{
166 browser->setSource( _path );
167 QMap<int, QString>::Iterator it = mHistory.begin();
168 bool exists = FALSE;
169 for ( ; it != mHistory.end(); ++it ) {
170 if ( *it == _path ) {
171 exists = TRUE;
172 break;
173 }
174 }
175 if ( !exists )
176 mHistory[ hist->insertItem( _path ) ] = _path;
177}
178
179void HelpWindow::readHistory()
180{
181 if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
182 QFile f( QDir::currentDirPath() + "/.history" );
183 f.open( IO_ReadOnly );
184 QDataStream s( &f );
185 s >> history;
186 f.close();
187 while ( history.count() > 20 )
188 history.remove( history.begin() );
189 }
190}
191
192void HelpWindow::readBookmarks()
193{
194 if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
195 QFile f( QDir::currentDirPath() + "/.bookmarks" );
196 f.open( IO_ReadOnly );
197 QDataStream s( &f );
198 s >> bookmarks;
199 f.close();
200 }
201}
202
203void HelpWindow::histChosen( int i )
204{
205 if ( mHistory.contains( i ) )
206 browser->setSource( mHistory[ i ] );
207}
208
209void HelpWindow::bookmChosen( int i )
210{
211 if ( mBookmarks.contains( i ) )
212 browser->setSource( mBookmarks[ i ] );
213}
214
215void HelpWindow::addBookmark()
216{
217 mBookmarks[ bookm->insertItem( caption() ) ] = caption();
218}
219