summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-gutenbrowser/gutenbrowserData.cpp
blob: ae1f69c42f4960fe0bf16c0097f79664c5a275bb (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
/***************************************************************************
                          gutenbrowser.cpp  -  description
                             -------------------
    begin                : Mon Jul 24 22:33:12 MDT 2000
    copyright            : (C) 2000 -2004 by llornkcor
    email                : ljp@llornkcor.com
***************************************************************************/
/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

//#include "gutenbrowserData.h"
#include "gutenbrowser.h"
#include "multiline_ex.h"

/* OPIE */
#include <opie2/odebug.h>
#include <opie2/oresource.h>

#include <qpe/config.h>
#include <qpe/fontdatabase.h>
#include <qpe/menubutton.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>

/* QT */
#include <qfontinfo.h>
#include <qtoolbutton.h>

void Gutenbrowser::initSlots() {

    connect(LibraryButton,SIGNAL(released()),SLOT(LibraryBtn()));
    connect(OpenButton,SIGNAL(released()),SLOT(OpenBtn()));
    connect(SearchButton,SIGNAL(released()),SLOT(SearchBtn()));
    connect(ForwardButton,SIGNAL(clicked()),SLOT(ForwardBtn()));
    connect(BackButton,SIGNAL(clicked()),SLOT(BackBtn()));
    connect(setBookmarkButton,SIGNAL(released()),SLOT(setBookmark()));
    connect(dictionaryButton,SIGNAL(released()),SLOT(LookupBtn()));
    connect(InfoBar,SIGNAL(clicked()),SLOT(InfoBarClick()));
    connect(qApp,SIGNAL(aboutToQuit()),SLOT(cleanUp()));
    connect(mainList,SIGNAL(clicked(QListBoxItem *)),SLOT(listClickedSlot(QListBoxItem *)));
    connect(bookmarksMenu,SIGNAL(activated(int)),SLOT(Bookmark(int)));
}

void Gutenbrowser::initConfig() {
//odebug << "Starting configuration." << oendl;
    QDir library(local_library);
    if ( !library.exists()) {
        library.mkdir(local_library, TRUE);
        QString msg;
// #ifndef Q_WS_WIN
        msg = "chmod 755 " + local_library;
        system(msg);
//     QDir pixdir(local_library+"pix");
//     if ( !pixdir.exists()) {
//         pixdir.mkdir(local_library+"pix", TRUE);
//         QString msg;
//         msg = "chmod 755 " + local_library+"pix";
//         system(msg);
//     }
// #endif

    }
      qDebug("init file is " + iniFile );;

#ifdef Q_WS_QWS
    useSplitter=FALSE;
    Config config("Gutenbrowser");

    config.setGroup( "General" );
//useWordWrap_CheckBox
    useIcons=TRUE;
#else

    config.setGroup( "General" );
    QString s_Split=config.readEntry("Splitter", "TRUE" );
    QWidget *d = QApplication::desktop();
    int width=d->width();
    int height=d->height();
    int w=0, h=0;
    QString str, str2;

    this->setMaximumWidth(width);

    if(s_Split=="TRUE")
        useSplitter=TRUE;
    else
        useSplitter=FALSE;

    config.setGroup( "Geometry" );
    if(width < 1030) {
        str = config.readEntry("Frame", "700,500");
        if(  !str.isEmpty() && str.find(',')>=0) {
            sscanf(str,"%d,%d",&w,&h);
            resize(w,h);
            str2.sprintf("%d,%d", (width-w)/2,(height-h)/2);
            str = config.readEntry( "Position", str2);
        } else {
            resize( 740,510 );
            str2.sprintf("%d,%d", (width-w)/2,(height-h)/2);
            str = config.readEntry( "Position",str2);
        }
    } else {// desktop is high res
        str = config.readEntry("Frame", "990,640");
        if(  !str.isEmpty() && str.find(',')>=0) {
            sscanf(str,"%d,%d",&w,&h);
            resize(w,h);
            str2.sprintf("%d,%d", (width-w)/2,(height-h)/2);
            str = config.readEntry( "Position", str2);
        } else {
            resize( 990,640 );
            str2.sprintf("%d,%d", (width-w)/2,(height-h)/2);
            str = config.readEntry( "Position", str2);
        }
    }
    int posX, posY;
    bool ok;
    QString goober;
    goober=str.left( str.find(",", 0, TRUE) );
    posX=goober.toInt( &ok, 10);
    goober=str.right( str.findRev(",", -1, TRUE) );
    posY= goober.toInt( &ok, 10);
//     move( posX, posY);
    str = config.readEntry("Icons", "TRUE");
    if(str == "TRUE")
        useIcons=TRUE;
    else
        useIcons=FALSE;
#endif
// #if defined(_WS_WIN_)
//     move( posX-4, posY-20);
// #endif

    config.setGroup( "Browser" );
    brow = config.readEntry( "Preferred", "Opera");
    config.setGroup( "FTPsite" );  // ftp server config
    ftp_host=config.readEntry("SiteName", "sailor.gutenberg.org");
//    ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(") ",0,TRUE)+1) );
    ftp_host=ftp_host.right(ftp_host.length()-(ftp_host.find(")        ",0,TRUE)+1) );
    ftp_host=ftp_host.stripWhiteSpace();

    ftp_base_dir= config.readEntry("base",  "/pub/gutenberg");

            //bool ok2;
    QString temp;
    QString copying;
    copying="";

    config.setGroup("General");
    QString qExit;
    qExit=config.readEntry("queryExit","TRUE");
    if(qExit=="TRUE") {
        b_queryExit=TRUE;
qDebug("lease query before leaving the library.");;
    } else {
			qDebug("Please DO NOT query before leaving the library.");
        b_queryExit=FALSE;
    }
// bookmarks
//       config.setGroup("Titles");
//      QString tmpTitle=config.readEntry(file_name,"");


}// end initConfig()

#define SCALED  Opie::Core::OResource::SmallIcon

void Gutenbrowser::initMenuBar()
{
	qDebug("Starting menu init.");
      // menuBar entry fileMenu
    menubar = new QPEMenuBar(this);

    fileMenu=new QPopupMenu();
    fileMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", SCALED ),
                         "Open Local Library...", this, SLOT( OpenBtn()) );
//    fileMenu->insertItem("Download FTPSite", this, SLOT( downloadFtpList()) );
    fileMenu->insertItem( Opie::Core::OResource::loadPixmap("home", SCALED ),
                          "Download Library Index", this, SLOT( downloadLibIndex()) );
    fileMenu->insertItem( Opie::Core::OResource::loadPixmap("quit",SCALED),
                          "Quit Gutenbrowser...", this, SLOT( ByeBye()) );
      // menuBar entry editMenu

    editMenu=new QPopupMenu();

    editMenu->insertItem( Opie::Core::OResource::loadPixmap("up", SCALED ), "Top",
                                                 this, SLOT(TopBtn()) );
    editMenu->insertItem( Opie::Core::OResource::loadPixmap("back",SCALED ), "Beginning",
                          this, SLOT(doBeginBtn()) );
    editMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/search",SCALED ), "Search",
                          this, SLOT(SearchBtn()) );

    editMenu->insertItem("Clear", this, SLOT(ClearEdit()) );

    optionsMenu= new QPopupMenu();
    optionsMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/configure",SCALED ),
                             "Configure", this, SLOT(doOptions()) );

    donateMenu = new QPopupMenu();
//     donateMenu->insertItem("Gutenberg", this, SLOT(donateGutenberg()) );
    donateMenu->insertItem( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", SCALED ),
                            "Gutenbrowser Developer", this, SLOT(infoGutenbrowser()) );

    menubar->insertItem("File", fileMenu);
    menubar->insertItem("Page", editMenu);
    menubar->insertItem("Options", optionsMenu);
//    menubar->insertItem("More Info", donateMenu);

    menu->addWidget( menubar,0);

    topLayout->addLayout( menu, 0);
}

void Gutenbrowser::initButtonBar()
{
//	qDebug("Starting buttonbar init.");

    OpenButton = new QPushButton( this, "OpenButton" );
    OpenButton->setFocusPolicy( QWidget::TabFocus );
    LibraryButton = new QPushButton( this, "LibraryButton" );
    LibraryButton->setFocusPolicy( QWidget::TabFocus );

    BackButton = new QPushButton( this, "BackButton" );
    BackButton->setFocusPolicy( QWidget::TabFocus );
    BackButton->setAutoRepeat(TRUE);

    ForwardButton = new QPushButton( this, "ForwardButton" );
    ForwardButton->setFocusPolicy( QWidget::TabFocus );
//    ForwardButton->setAutoRepeat(TRUE);

    SearchButton = new QPushButton( this, "SearchButton" );
    SearchButton->setFocusPolicy( QWidget::TabFocus );

    setBookmarkButton = new QPushButton( this, "setBookmark" );
    setBookmarkButton->setFocusPolicy( QWidget::TabFocus );

    lastBmkButton = new MenuButton( this, "lastBmkButton" );
    lastBmkButton->setFocusPolicy( QWidget::TabFocus );

    bookmarksMenu = new QPopupMenu();
    bookmarksMenu->insertItem("Last Set", this, SLOT(Bookmark( int) ));

    lastBmkButton->setPopup(bookmarksMenu);

    dictionaryButton = new QPushButton( this, "dictionaryButton" );
    dictionaryButton->setFocusPolicy( QWidget::TabFocus );

    InfoBar = new QPushButton( this, "Info_Bar" );
//    if(!useSplitter) {

    buttonsHidden=false;

    buttons2->addWidget(OpenButton, 0, AlignCenter);
    buttons2->addWidget(LibraryButton, 0, AlignCenter);
    buttons2->addWidget(BackButton, 0, AlignCenter);
    buttons2->addWidget(ForwardButton, 0, AlignCenter);
    buttons2->addWidget(SearchButton, 0, AlignCenter);
    buttons2->addWidget(setBookmarkButton, 0, AlignCenter);
    buttons2->addWidget(lastBmkButton, 0, AlignCenter);
    buttons2->addWidget(dictionaryButton, 0, AlignCenter);
    buttons2->addWidget(InfoBar, 0, AlignCenter);
    buttons2->addStretch(5);
    buttons2->setSpacing(5);

    topLayout->addLayout( buttons2,0);
}

/* STATUSBAR*/
void Gutenbrowser::initStatusBar()
{
	qDebug("statusbar");
// #ifndef Q_WS_QWS

//     statusBar = new QStatusBar( this, "Status Bar");
//     statusBar->message(IDS_STATUS_DEFAULT, 2000);
// #endif
}

void Gutenbrowser::initView()
{
      // set the main widget here
//        QFont defaultFont( "charter", 10, 50, 0 );
    Lview = new MultiLine_Ex(this);
    Config cfg("Gutenbrowser");
    cfg.setGroup("Font");

    FontDatabase fdb;
    QFont defaultFont = Lview->font();
    QFontInfo fontInfo(defaultFont);

    QString family = cfg.readEntry("Family", fontInfo.family());
    QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
    int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
    QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );

    defaultFont = fdb.font(family,style,i_size,charSet);

    QString italic = cfg.readEntry("Italic","FALSE");
    if(italic=="TRUE") {
        qDebug("Set Italic font");;
        defaultFont = fdb.font( family, "Regular", i_size,charSet); //workaround
        defaultFont.setItalic(TRUE);
    }

    Lview->setFont( defaultFont);
    update();

    cfg.setGroup("General");

    if( cfg.readBoolEntry("WordWrap", 1)) {
        Lview->setWordWrap(QMultiLineEdit::WidgetWidth);
        useWrap=true;
    } else {
        Lview->setWordWrap(QMultiLineEdit::NoWrap);
        useWrap = false;
    }
    mainList = new QListBox(this,"mainlist");
		mainList->hide();
//  QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold);
      //  mainList->showMaximized();
//  mainList->setGeometry(2,30,230,160);
    Lview->setReadOnly( true);
    edits->addWidget( Lview);
    edits->addWidget(mainList);

//     if(!showMainList) {
//         Lview->setText( "\nThis is gutenbrowser for the Sharp Zaurus.\nMake your self at home, sit back, relax and read something great. ");
//     }
//		else
//        Lview->hide();

    topLayout->addLayout( edits, 0);
		qDebug("end initView");
}

void Gutenbrowser::hideView() {
//		qWarning("Hide View");
		mainList->show();
		Lview->hide();
}