~ubuntu-branches/ubuntu/raring/muse/raring-proposed

« back to all changes in this revision

Viewing changes to help.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//=========================================================
2
2
//  MusE
3
3
//  Linux Music Editor
4
 
//  $Id: help.cpp,v 1.1 2002/01/30 14:10:07 muse Exp $
 
4
//  $Id: help.cpp,v 1.1.1.1 2003/10/29 10:05:18 wschweer Exp $
5
5
//
6
6
//  (C) Copyright 1999/2000 Werner Schweer (ws@seh.de)
7
7
//=========================================================
8
8
 
9
9
#include "app.h"
10
 
#include "help.h"
11
10
#include "globals.h"
12
11
#include "icons.h"
13
 
 
14
 
#include <stack>
15
 
#include <qstatusbar.h>
16
 
#include <qpixmap.h>
17
 
#include <qpopupmenu.h>
18
 
#include <qmenubar.h>
19
 
#include <qtoolbar.h>
20
 
#include <qtoolbutton.h>
21
 
#include <qiconset.h>
22
 
#include <qfile.h>
23
 
#include <qtextstream.h>
24
 
#include <qstylesheet.h>
25
12
#include <qmessagebox.h>
26
 
#include <qfiledialog.h>
27
 
#include <qapplication.h>
28
 
#include <qcombobox.h>
29
 
#include <qevent.h>
30
 
#include <qlineedit.h>
31
 
#include <qobjectlist.h>
32
 
#include <qfileinfo.h>
33
 
#include <qfile.h>
34
 
#include <qdatastream.h>
35
 
#include <qprinter.h>
36
 
#include <qsimplerichtext.h>
37
 
#include <qpaintdevicemetrics.h>
38
 
#include <qsplitter.h>
39
 
#include <qlistbox.h>
40
 
#include <qtabwidget.h>
41
 
#include <qpainter.h>
42
 
#include <qlistview.h>
43
 
// #include <fcntl.h>
 
13
 
44
14
#include <unistd.h>
45
15
 
46
 
#include <ctype.h>
47
 
 
48
 
struct Contents {
49
 
      const char* name;
50
 
      const char* url;
51
 
      };
52
 
 
53
 
static const Contents contents[] = {
54
 
      { "Arranger", "arranger.html" },
55
 
      { "Pianoroll Editor", "pianoroll.html" },
56
 
      { "Drum Editor", "drumedit.html" },
57
 
      { "List Editor", "listedit.html" },
58
 
      { "ScoreEditor", "scoreedit.html" },
59
 
      { "Transport Panel", "transport.html" },
60
 
      { "Create New Song", "newsong.html" },
61
 
      { "Record Events", "record.html" },
62
 
      { "Step Recording", "steprecord.html" },
63
 
      { 0, 0, }
64
 
      };
65
 
 
66
 
//---------------------------------------------------------
67
 
//   helpViewer
68
 
//---------------------------------------------------------
69
 
 
70
 
void MusE::helpBrowser()
 
16
//---------------------------------------------------------
 
17
//   startHelpBrowser
 
18
//---------------------------------------------------------
 
19
 
 
20
void MusE::startHelpBrowser()
71
21
      {
72
 
      if (helpViewer == 0) {
73
 
            QString lang = getenv("LANG");
74
 
            QString museHelp = museGlobalShare + "/html/toc_" + lang + ".txt";
 
22
      QString lang(getenv("LANG"));
 
23
      QString museHelp = museGlobalShare + QString("/html/index_") + lang + QString(".html");
 
24
      if (access(museHelp.latin1(), R_OK) != 0) {
 
25
              museHelp = museGlobalShare + QString("/html/index.html");
75
26
            if (access(museHelp.latin1(), R_OK) != 0) {
76
27
                  QString info(tr("no help found at: "));
77
28
                  info += museHelp;
78
29
                  QMessageBox::critical(this, tr("MusE: Open Help"), info);
79
30
                  return;
80
31
                  }
81
 
            helpViewer = new HelpWindow(museHelp, museGlobalShare + "/html");
82
 
            }
83
 
      helpViewer->show();
84
 
      }
85
 
 
86
 
//---------------------------------------------------------
87
 
//   HelpWindow
88
 
//---------------------------------------------------------
89
 
 
90
 
HelpWindow::HelpWindow(const QString& home_, const QString& _path, QWidget* parent, const char *name)
91
 
   : MainWindow(parent, name, WType_TopLevel)
92
 
      {
93
 
      readBookmarks();
94
 
 
95
 
      fileList = path.entryList();
96
 
 
97
 
      QSplitter* split = new QSplitter(this);
98
 
      setCentralWidget(split);
99
 
 
100
 
      tab  = new QTabWidget(split);
101
 
      tab->setMinimumWidth(10);
102
 
      split->setResizeMode(tab, QSplitter::Stretch);
103
 
 
104
 
      contentsList  = new QListView(tab, "toc");
105
 
      contentsList->setRootIsDecorated(true);
106
 
      contentsList->setSelectionMode(QListView::Single);
107
 
      contentsList->setSorting(-1, false);
108
 
      contentsList->addColumn(tr("Table of Contents"));
109
 
      connect(contentsList, SIGNAL(clicked(QListViewItem*)),
110
 
         this, SLOT(contentsSelected(QListViewItem*)));
111
 
 
112
 
      indexList     = new QListBox(tab, "indexlist");
113
 
      bookmarkList  = new QListBox(tab, "bookmarks");
114
 
      connect(bookmarkList, SIGNAL(clicked(QListBoxItem*)),
115
 
         this, SLOT(bookmarkSelected(QListBoxItem*)));
116
 
 
117
 
      //
118
 
      //  read index
119
 
      //
120
 
      FILE* f = fopen(home_.latin1(), "r");
121
 
      if (f == 0) {
122
 
            QString info(tr("no help found at: "));
123
 
            info += home_;
124
 
            QMessageBox::critical(this, tr("MusE: Open index"), info);
125
 
            return;
126
 
            }
127
 
      std::stack<QListViewItem*> istack;
128
 
      int level = 0;
129
 
      while (!feof(f)) {
130
 
            bool expandable = false;
131
 
            int nlevel = 0;
132
 
            char buffer[1024];
133
 
            char* p1 = fgets(buffer, 1024, f);
134
 
            if (p1 == 0)
135
 
                  break;
136
 
            if (*p1 == 0 || *p1 == '\n' || *p1 == '#')
137
 
                  continue;
138
 
            while (isspace(*p1)) {
139
 
                  ++p1;
140
 
                  ++nlevel;
141
 
                  }
142
 
            if (*p1 == '+') {
143
 
                  expandable = true;
144
 
                  ++p1;
145
 
                  }
146
 
            while (isspace(*p1))
147
 
                  ++p1;
148
 
            bool quotes = false;
149
 
            if (*p1 == '"') {
150
 
                  quotes = true;
151
 
                  ++p1;
152
 
                  }
153
 
            if (nlevel > level)
154
 
                  nlevel = level;
155
 
            if (nlevel < level) {
156
 
                  while (!istack.empty() && nlevel < level) {
157
 
                        istack.pop();
158
 
                        --level;
159
 
                        }
160
 
                  level = nlevel;
161
 
                  }
162
 
            char* p2 = p1;
163
 
            ++p2;
164
 
            while(*p2) {
165
 
                  if (quotes) {
166
 
                        if (*p2 == '"')
167
 
                              break;
168
 
                        }
169
 
                  else {
170
 
                        if (isspace(*p2))
171
 
                              break;
172
 
                        }
173
 
                  ++p2;
174
 
                  }
175
 
            *p2 = 0;
176
 
            ++p2;
177
 
            while(isspace(*p2))
178
 
                  ++p2;
179
 
            QListViewItem* item;
180
 
            QString qp1(p1);
181
 
            QString qp2(p2);
182
 
            qp2 = qp2.stripWhiteSpace();
183
 
            if (qp2[0] == '"')
184
 
                  qp2 = qp2.mid(1, qp2.length()-2);
185
 
            if (level)
186
 
                  item = new QListViewItem(istack.top(), qp1, qp2);
187
 
            else
188
 
                  item = new QListViewItem(contentsList, qp1, qp2);
189
 
            if (expandable) {
190
 
                  item->setExpandable(true);
191
 
                  istack.push(item);
192
 
                  level = nlevel+1;
193
 
                  }
194
 
            }
195
 
      fclose(f);
196
 
      tab->addTab(contentsList, tr("TOC"));
197
 
 
198
 
      tab->addTab(indexList, tr("IDX"));
199
 
      tab->addTab(bookmarkList, tr("BM"));
200
 
      browser = new QTextBrowser(split);
201
 
      QValueList<int> sizes;
202
 
      sizes.append(140);
203
 
      sizes.append(610);
204
 
      split->setSizes(sizes);
205
 
 
206
 
      browser->mimeSourceFactory()->setFilePath(_path);
207
 
      browser->setFrameStyle(QFrame::Panel | QFrame::Sunken);
208
 
      connect(browser, SIGNAL(textChanged()), SLOT(textChanged()));
209
 
      connect(browser, SIGNAL(highlighted(const QString&)),
210
 
             statusBar(), SLOT(message(const QString&)));
211
 
 
212
 
      resize(750,700);
213
 
      setToolBarsMovable(false);
214
 
 
215
 
      QPopupMenu* file = new QPopupMenu(this);
216
 
      file->insertItem(tr("&New Window"), this, SLOT(newWindow()), ALT | Key_N);
217
 
      file->insertItem(tr("&Open File"), this, SLOT(openFile()), ALT | Key_O);
218
 
      file->insertItem(tr("&Print"), this, SLOT(print()), ALT | Key_P);
219
 
      file->insertSeparator();
220
 
      file->insertItem(tr("&Close"), this, SLOT(close()), ALT | Key_Q);
221
 
      file->insertItem(tr("E&xit"), qApp, SLOT(closeAllWindows()), ALT | Key_X);
222
 
 
223
 
      //---------Actions----------------------------
224
 
      QAction* backward = new QAction("backward",
225
 
         QIconSet(*backIcon), "&Backward",
226
 
        0, this, "backward");
227
 
      connect(backward, SIGNAL(activated()), browser, SLOT(backward()));
228
 
 
229
 
      QAction* forward = new QAction("forward",
230
 
         QIconSet(*forwardIcon), "&Forward",
231
 
        0, this, "forward");
232
 
      connect(forward, SIGNAL(activated()), browser, SLOT(forward()));
233
 
 
234
 
      QPopupMenu* go = new QPopupMenu(this);
235
 
      backward->addTo(go);
236
 
      forward->addTo(go);
237
 
      go->insertItem(*homeIcon, tr("&Home"), browser, SLOT(home()));
238
 
 
239
 
      bookm = new QPopupMenu(this);
240
 
      bookm->insertItem(tr("Add Bookmark"), this, SLOT(addBookmark()));
241
 
      bookm->insertSeparator();
242
 
 
243
 
      QStringList::Iterator it2 = bookmarks.begin();
244
 
      for ( ; it2 != bookmarks.end(); ++it2 ) {
245
 
            mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
246
 
            bookmarkList->insertItem(*it2);
247
 
            }
248
 
 
249
 
      connect(bookm, SIGNAL(activated(int)), SLOT(bookmChosen(int)));
250
 
 
251
 
      menuBar()->insertItem(tr("&File"), file);
252
 
      menuBar()->insertItem(tr("&Go"), go);
253
 
      menuBar()->insertItem(tr( "Bookmarks"), bookm);
254
 
      menuBar()->insertSeparator();
255
 
 
256
 
      connect(browser, SIGNAL(backwardAvailable(bool)),
257
 
         backward, SLOT(setEnabled(bool)));
258
 
      connect(browser, SIGNAL(forwardAvailable(bool)),
259
 
         forward, SLOT(setEnabled(bool)));
260
 
 
261
 
      QToolBar* toolbar = new QToolBar(this);
262
 
      addToolBar(toolbar, "Toolbar");
263
 
      QToolButton* button;
264
 
 
265
 
      backward->addTo(toolbar);
266
 
      forward->addTo(toolbar);
267
 
 
268
 
      button = new QToolButton(*homeIcon, tr("Home"), "", browser, SLOT(home()), toolbar);
269
 
 
270
 
      toolbar->addSeparator();
271
 
      button = new QToolButton(toolbar);
272
 
      button->setToggleButton(true);
273
 
      button->setPixmap(*tocIcon);
274
 
      button->setOn(true);
275
 
      connect(button, SIGNAL(toggled(bool)), SLOT(toggleToc(bool)));
276
 
      toolbar->addSeparator();
277
 
 
278
 
      pathCombo = new QComboBox(true, toolbar );
279
 
      connect( pathCombo, SIGNAL( activated( const QString & ) ),
280
 
         this, SLOT( pathSelected( const QString & ) ) );
281
 
      toolbar->setStretchableWidget( pathCombo );
282
 
      setRightJustification(true);
283
 
      setDockEnabled( Left, false);
284
 
      setDockEnabled( Right, false);
285
 
 
286
 
      pathCombo->insertItem( home_ );
287
 
      pathCombo->installEventFilter( this );
288
 
      QObjectList *l = queryList( "QLineEdit" );
289
 
      if ( l && l->first() )
290
 
            ( (QLineEdit*)l->first() )->installEventFilter( this );
291
 
 
292
 
      browser->setFocus();
293
 
      contentsSelected(contentsList->firstChild());
294
 
//      if (!home_.isEmpty())
295
 
//            browser->setSource(home_);
296
 
      }
297
 
 
298
 
//---------------------------------------------------------
299
 
//   bookmarkSelected
300
 
//---------------------------------------------------------
301
 
 
302
 
void HelpWindow::bookmarkSelected(QListBoxItem* item)
303
 
      {
304
 
      browser->setSource(item->text());
305
 
      }
306
 
 
307
 
//---------------------------------------------------------
308
 
//   contentsSelected
309
 
//---------------------------------------------------------
310
 
 
311
 
void HelpWindow::contentsSelected(QListViewItem* item)
312
 
      {
313
 
      if (item) {
314
 
//            printf("<%s> - <%s>\n", item->text(0).latin1(), item->text(1).latin1());
315
 
            browser->setSource(item->text(1));
316
 
            }
317
 
      }
318
 
 
319
 
//---------------------------------------------------------
320
 
//   HelpWindow
321
 
//---------------------------------------------------------
322
 
 
323
 
HelpWindow::~HelpWindow()
324
 
      {
325
 
      bookmarks.clear();
326
 
      QMap<int, QString>::Iterator it2 = mBookmarks.begin();
327
 
      for ( ; it2 != mBookmarks.end(); ++it2 )
328
 
            bookmarks.append( *it2 );
329
 
 
330
 
      QFile f2( QDir::currentDirPath() + "/.bookmarks" );
331
 
      f2.open( IO_WriteOnly );
332
 
      QDataStream s2( &f2 );
333
 
      s2 << bookmarks;
334
 
      f2.close();
335
 
      }
336
 
 
337
 
//---------------------------------------------------------
338
 
//   textChanged
339
 
//---------------------------------------------------------
340
 
 
341
 
void HelpWindow::textChanged()
342
 
      {
343
 
      if (browser->documentTitle().isNull())
344
 
            setCaption(browser->context());
345
 
      else
346
 
            setCaption(browser->documentTitle());
347
 
      selectedURL = caption();
348
 
      if (!selectedURL.isEmpty() && pathCombo) {
349
 
            path = QDir(QFileInfo(selectedURL).dirPath(true), "*.html *.htm");
350
 
            fileList = path.entryList();
351
 
            bool exists = false;
352
 
            int i;
353
 
            for (i = 0; i < pathCombo->count(); ++i) {
354
 
                  if (pathCombo->text(i) == selectedURL) {
355
 
                        exists = true;
356
 
                        break;
357
 
                        }
358
 
                  }
359
 
            if (!exists) {
360
 
                  pathCombo->insertItem(selectedURL, 0);
361
 
                  pathCombo->setCurrentItem(0);
362
 
                  }
363
 
            else
364
 
                  pathCombo->setCurrentItem(i);
365
 
            selectedURL = QString::null;
366
 
            }
367
 
      }
368
 
 
369
 
//---------------------------------------------------------
370
 
//   openFile
371
 
//---------------------------------------------------------
372
 
 
373
 
void HelpWindow::openFile()
374
 
      {
375
 
      QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
376
 
      if ( !fn.isEmpty() )
377
 
            browser->setSource(fn);
378
 
      }
379
 
 
380
 
//---------------------------------------------------------
381
 
//   newWindow
382
 
//---------------------------------------------------------
383
 
 
384
 
void HelpWindow::newWindow()
385
 
      {
386
 
      (new HelpWindow(browser->source(), "qbrowser"))->show();
387
 
      }
388
 
 
389
 
//---------------------------------------------------------
390
 
//   print
391
 
//---------------------------------------------------------
392
 
 
393
 
void HelpWindow::print()
394
 
      {
395
 
      QPrinter printer;
396
 
      printer.setFullPage(true);
397
 
      if ( printer.setup() ) {
398
 
            QPainter p( &printer );
399
 
            QPaintDeviceMetrics metrics(p.device());
400
 
            int dpix = metrics.logicalDpiX();
401
 
            int dpiy = metrics.logicalDpiY();
402
 
            const int margin = 72; // pt
403
 
            QRect body(margin*dpix/72, margin*dpiy/72,
404
 
                   metrics.width()-margin*dpix/72*2,
405
 
                   metrics.height()-margin*dpiy/72*2 );
406
 
            double scale = 0.75;
407
 
            p.scale(scale, scale );
408
 
            body = QRect( int(body.x()/scale), int(body.y()/scale),
409
 
                      int(body.width()/scale), int(body.height()/scale) );
410
 
            QFont font("times");
411
 
            QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
412
 
               browser->mimeSourceFactory(), body.height() );
413
 
            richText.setWidth( &p, body.width() );
414
 
            QRect view( body );
415
 
            int page = 1;
416
 
            do {
417
 
                  richText.draw( &p, body.left(), body.top(), view, colorGroup() );
418
 
                  view.moveBy( 0, body.height() );
419
 
                  p.translate( 0 , -body.height() );
420
 
                  p.setFont( font );
421
 
                  p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
422
 
                     view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
423
 
                  if ( view.top()  >= richText.height() )
424
 
                        break;
425
 
                  printer.newPage();
426
 
                  page++;
427
 
                  } while (true);
428
 
            }
429
 
      }
430
 
 
431
 
//---------------------------------------------------------
432
 
//   pathSelected
433
 
//---------------------------------------------------------
434
 
 
435
 
void HelpWindow::pathSelected(const QString &_path)
436
 
      {
437
 
      browser->setSource( _path );
438
 
      path = QDir(QFileInfo(_path).dirPath(true), "*.html *.htm");
439
 
      fileList = path.entryList();
440
 
      QMap<int, QString>::Iterator it = mHistory.begin();
441
 
      bool exists = false;
442
 
      for ( ; it != mHistory.end(); ++it) {
443
 
            if ( *it == _path ) {
444
 
                  exists = true;
445
 
                  break;
446
 
                  }
447
 
            }
448
 
      }
449
 
 
450
 
//---------------------------------------------------------
451
 
//   eventFilter
452
 
//---------------------------------------------------------
453
 
 
454
 
bool HelpWindow::eventFilter( QObject * o, QEvent * e )
455
 
      {
456
 
      if ( QMainWindow::eventFilter( o, e ) )
457
 
            return true;
458
 
 
459
 
      QObjectList *l = queryList( "QLineEdit" );
460
 
      if ( !l || !l->first() )
461
 
            return false;
462
 
 
463
 
      QLineEdit *lined = (QLineEdit*)l->first();
464
 
 
465
 
      if (( o == pathCombo || o == lined) &&
466
 
         e->type() == QEvent::KeyPress) {
467
 
 
468
 
//TODO            if ( isprint(((QKeyEvent *)e)) ) {
469
 
            if (1) {
470
 
                  if ( lined->hasMarkedText() )
471
 
                        lined->del();
472
 
                  QString nt( lined->text() );
473
 
                  nt.remove( 0, nt.findRev( '/' ) + 1 );
474
 
                  nt.truncate( lined->cursorPosition() );
475
 
                  nt += (char)(((QKeyEvent *)e));
476
 
 
477
 
                  QStringList::Iterator it = fileList.begin();
478
 
                  while ( it != fileList.end() && (*it).left( nt.length() ) != nt )
479
 
                        ++it;
480
 
 
481
 
                  if (!(*it).isEmpty()) {
482
 
                        nt = *it;
483
 
                        int cp = lined->cursorPosition() + 1;
484
 
                        int l = path.canonicalPath().length() + 1;
485
 
                        lined->validateAndSet( path.canonicalPath() + "/" + nt, cp, cp, l + nt.length() );
486
 
                        return true;
487
 
                        }
488
 
                  }
489
 
            }
490
 
      return false;
491
 
      }
492
 
 
493
 
//---------------------------------------------------------
494
 
//   readBookmark
495
 
//---------------------------------------------------------
496
 
 
497
 
void HelpWindow::readBookmarks()
498
 
      {
499
 
      if (QFile::exists( QDir::currentDirPath() + "/.bookmarks")) {
500
 
            QFile f( QDir::currentDirPath() + "/.bookmarks" );
501
 
            f.open( IO_ReadOnly );
502
 
            QDataStream s( &f );
503
 
            s >> bookmarks;
504
 
            f.close();
505
 
            }
506
 
      }
507
 
 
508
 
//---------------------------------------------------------
509
 
//   bookmChosen
510
 
//---------------------------------------------------------
511
 
 
512
 
void HelpWindow::bookmChosen(int i)
513
 
      {
514
 
      if (mBookmarks.contains(i))
515
 
            browser->setSource(mBookmarks[ i ]);
516
 
      }
517
 
 
518
 
//---------------------------------------------------------
519
 
//   addBookmark
520
 
//---------------------------------------------------------
521
 
 
522
 
void HelpWindow::addBookmark()
523
 
      {
524
 
      mBookmarks[bookm->insertItem(caption())] = caption();
525
 
      }
526
 
 
527
 
//---------------------------------------------------------
528
 
//   toggleToc
529
 
//---------------------------------------------------------
530
 
 
531
 
void HelpWindow::toggleToc(bool flag)
532
 
      {
533
 
      if (flag)
534
 
            tab->show();
535
 
      else
536
 
            tab->hide();
 
32
            }
 
33
      if (fork() == 0) {
 
34
            execlp(helpBrowser.latin1(), helpBrowser.latin1(), museHelp.latin1(), 0);
 
35
            }
537
36
      }
538
37