~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kscd/kscd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
Import upstream version 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Kscd - A simple cd player for the KDE Project
 
3
 *
 
4
 * $Id: kscd.cpp,v 1.134 2001/07/27 11:35:28 mlaurent Exp $
 
5
 *
 
6
 * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 *
 
22
 */
 
23
 
 
24
#include <qdir.h>
 
25
#include <qregexp.h>
 
26
#include <qtextstream.h>
 
27
#include <qlayout.h>
 
28
 
 
29
#include <dcopclient.h>
 
30
#include <kaboutdata.h>
 
31
#include <kcharsets.h>
 
32
#include <kcmdlineargs.h>
 
33
#include <kconfig.h>
 
34
#include <kdebug.h>
 
35
#include <kemailsettings.h>
 
36
#include <kglobal.h>
 
37
#include <kiconloader.h>
 
38
#include <klocale.h>
 
39
#include <kmessagebox.h>
 
40
#include <kprotocolmanager.h>
 
41
#include <krun.h>
 
42
#include <krandomsequence.h>
 
43
#include <kstddirs.h>
 
44
#include <kstringhandler.h>
 
45
#include <kurl.h>
 
46
 
 
47
#include "docking.h"
 
48
#include "kscd.h"
 
49
#include "configdlg.h"
 
50
#include "mgconfdlg.h"
 
51
#include "version.h"
 
52
extern "C" {
 
53
    // We don't have libWorkMan installed already, so get everything
 
54
    // from within our own directory
 
55
#include "libwm/include/workman.h"
 
56
}
 
57
#include "libwm/include/wm_config.h"
 
58
#include "inexact.h"
 
59
#include "CDDialog.h"
 
60
#include "CDDBSetup.h"
 
61
#include "bitmaps/playpaus.xbm"
 
62
#include "bitmaps/stop.xbm"
 
63
#include "bitmaps/repeat.xbm"
 
64
#include "bitmaps/nexttrk.xbm"
 
65
#include "bitmaps/prevtrk.xbm"
 
66
#include "bitmaps/ff.xbm"
 
67
#include "bitmaps/rew.xbm"
 
68
#include "bitmaps/info.xbm"
 
69
#include "bitmaps/poweroff.xbm"
 
70
#include "bitmaps/magic.xbm"
 
71
#include "bitmaps/eject.xbm"
 
72
#include "bitmaps/db.xbm"
 
73
#include "bitmaps/logo.xbm"
 
74
#include "bitmaps/shuffle.xbm"
 
75
#include "bitmaps/options.xbm"
 
76
 
 
77
static const char *description = I18N_NOOP("KDE CD player");
 
78
 
 
79
DockWidget*     dock_widget;
 
80
SMTP                *smtpMailer;
 
81
bool dockinginprogress = 0;
 
82
bool quitPending = 0;
 
83
bool stoppedByUser = 1;
 
84
bool device_change = false;
 
85
 
 
86
char            tmptime[100];
 
87
char            *tottime;
 
88
//static void   playtime (void);
 
89
void            kcderror(const QString& title, const QString& message);
 
90
void            kcdworker(int );
 
91
 
 
92
//void          parseargs(char* buf, char** args);
 
93
extern QTime framestoTime(int frames);
 
94
extern void cddb_decode(QString& str);
 
95
extern void cddb_encode(QString& str, QStringList &returnlist);
 
96
extern void cddb_playlist_encode(QStringList& list,QString& playstr);
 
97
extern bool cddb_playlist_decode(QStringList& list, QString& str);
 
98
 
 
99
int    random_current;  /* koz: Current track in random list */
 
100
int   *random_list;     /* koz: Used in Random - once through */
 
101
 
 
102
KRandomSequence randSequence;
 
103
 
 
104
static QString formatTrack(int d1, int d2)
 
105
{
 
106
  QString str = QString::fromLatin1("%1/%2")
 
107
    .arg( QString::number(d1).rightJustify(2, '0') )
 
108
    .arg( QString::number(d2).rightJustify(2, '0') );
 
109
  return str;
 
110
}
 
111
 
 
112
int cddb_error = 0;
 
113
 
 
114
/****************************************************************************
 
115
                                          The GUI part
 
116
*****************************************************************************/
 
117
 
 
118
KSCD::KSCD( QWidget *parent, const char *name )
 
119
  :   QWidget( parent, name ), DCOPObject("CDPlayer")
 
120
{
 
121
  //    connect(kapp, SIGNAL (saveYourself() ), SLOT (doSM()));
 
122
  magicproc           = 0L;
 
123
  cd_device_str       = "";
 
124
  background_color    = black;
 
125
  led_color           = green;
 
126
  randomplay          = false;
 
127
  looping             = false;
 
128
  cddrive_is_ok       = true;
 
129
  tooltips            = true;
 
130
  magic_width         = 330;
 
131
  magic_height        = 135;
 
132
  magic_brightness    = 3;
 
133
  magic_pointsAreDiamonds = false;
 
134
 
 
135
  cycle_flag          = false;
 
136
  cddb_remote_enabled = false;
 
137
  cddb_auto_enabled   = false;
 
138
  setup               = 0L;
 
139
  smtpconfig          = 0L;
 
140
  time_display_mode   = TRACK_SEC;
 
141
  cddb_inexact_sentinel = false;
 
142
  revision            = 0; // The first freedb revision is "0"
 
143
  use_kfm             = true;
 
144
  docking             = true;
 
145
  autoplay            = false;
 
146
  stopexit            = true;
 
147
  ejectonfinish       = false;
 
148
  randomonce          = true;
 
149
  updateDialog        = false;
 
150
  ejectedBefore       = false;
 
151
  currentlyejected    = false;
 
152
  cddialog        = 0L;
 
153
 
 
154
  have_new_cd = true;
 
155
 
 
156
  drawPanel();
 
157
  loadBitmaps();
 
158
  setColors();
 
159
  setToolTips();
 
160
 
 
161
  timer           = new QTimer( this );
 
162
  queryledtimer   = new QTimer( this );
 
163
  titlelabeltimer = new QTimer( this );
 
164
  initimer        = new QTimer( this );
 
165
  cycletimer      = new QTimer( this );
 
166
 
 
167
  connect( initimer, SIGNAL(timeout()),this,  SLOT(initCDROM()) );
 
168
  connect( queryledtimer, SIGNAL(timeout()),  SLOT(togglequeryled()) );
 
169
  connect( titlelabeltimer, SIGNAL(timeout()),  SLOT(titlelabeltimeout()) );
 
170
  connect( cycletimer, SIGNAL(timeout()),  SLOT(cycletimeout()) );
 
171
  connect( timer, SIGNAL(timeout()),  SLOT(cdMode()) );
 
172
  connect( playPB, SIGNAL(clicked()), SLOT(playClicked()) );
 
173
  connect( stopPB, SIGNAL(clicked()), SLOT(stopClicked()) );
 
174
  connect( prevPB, SIGNAL(clicked()), SLOT(prevClicked()) );
 
175
  connect( nextPB, SIGNAL(clicked()), SLOT(nextClicked()) );
 
176
  connect( fwdPB, SIGNAL(clicked()), SLOT(fwdClicked()) );
 
177
  connect( bwdPB, SIGNAL(clicked()), SLOT(bwdClicked()) );
 
178
  connect( dockPB, SIGNAL(clicked()), SLOT(quitClicked()) );
 
179
#if KSCDMAGIC
 
180
  connect( magicPB, SIGNAL(clicked()), SLOT(magicslot()) );
 
181
#endif
 
182
  connect( replayPB, SIGNAL(clicked()), SLOT(loopClicked()) );
 
183
  connect( ejectPB, SIGNAL(clicked()), SLOT(ejectClicked()) );
 
184
  connect( songListCB, SIGNAL(activated(int)), SLOT(trackSelected(int)));
 
185
  connect( volSB, SIGNAL(valueChanged(int)), SLOT(volChanged(int)));
 
186
  connect( aboutPB, SIGNAL(clicked()), SLOT(cycleplaytimemode()));
 
187
  //connect( aboutPB, SIGNAL(clicked()), SLOT(aboutClicked()));
 
188
  connect( optionsbutton, SIGNAL(clicked()), SLOT(aboutClicked()));
 
189
  connect( shufflebutton, SIGNAL(clicked()), SLOT(randomSelected()));
 
190
  connect( cddbbutton, SIGNAL(clicked()), SLOT(CDDialogSelected()));
 
191
  connect(kapp,SIGNAL(kdisplayPaletteChanged()),this,SLOT(setColors()));
 
192
 
 
193
  readSettings();
 
194
  setColors();
 
195
  initWorkMan();
 
196
 
 
197
  setupPopups();
 
198
  volstartup = TRUE;
 
199
  volSB->setValue(volume);
 
200
 
 
201
  if(looping)
 
202
    {
 
203
      loopled->on();
 
204
    }
 
205
 
 
206
  dock_widget = new DockWidget( this, "dockw");
 
207
  if(docking)
 
208
    {
 
209
      dock_widget->show();
 
210
        connect(this, SIGNAL(trackChanged(const QString&)), dock_widget, SLOT(setToolTip(const QString&)));
 
211
    }
 
212
 
 
213
  smtpMailer = new SMTP;
 
214
  connect(smtpMailer, SIGNAL(messageSent()), this, SLOT(smtpMessageSent()));
 
215
  connect(smtpMailer, SIGNAL(error(int)), this, SLOT(smtpError(int)));
 
216
 
 
217
  setFocusPolicy ( QWidget::NoFocus );
 
218
 
 
219
  initimer->start(500,TRUE);
 
220
} // KSCD
 
221
 
 
222
void
 
223
KSCD::smtpMessageSent(void)
 
224
{
 
225
  KMessageBox::information(this, i18n("Record submitted successfully"),
 
226
                           i18n("Record Submission"));
 
227
} // smtpMessageSent()
 
228
 
 
229
/**
 
230
 * Interpret error codes from the SMTP mailer.
 
231
 */
 
232
void
 
233
KSCD::smtpError(int errornum)
 
234
{
 
235
  QString str, lstr;
 
236
 
 
237
  switch(errornum){
 
238
  case 10:
 
239
    lstr = i18n("Error connecting to server.");
 
240
    break;
 
241
  case 11:
 
242
    lstr = i18n("Not connected.");
 
243
    break;
 
244
  case 15:
 
245
    lstr = i18n("Connection timed out.");
 
246
    break;
 
247
  case 16:
 
248
    lstr = i18n("Time out waiting for server interaction.");
 
249
    break;
 
250
  default:
 
251
    lstr = i18n("Server said:\n\"%1\"").arg(smtpMailer->getLastLine());
 
252
  }
 
253
  str = i18n("Error #%1 sending message via SMTP.\n\n%2")
 
254
    .arg(errornum).arg(lstr);
 
255
  KMessageBox::error(this, str, i18n("Record Submission"));
 
256
} // smptError()
 
257
 
 
258
 
 
259
/**
 
260
 * Initialize the variables only in WorkMan
 
261
 * FIXME: What is needed exactly?
 
262
 */
 
263
void
 
264
KSCD::initWorkMan()
 
265
{
 
266
  fastin       = FALSE;
 
267
  scmd         = 0;
 
268
  tmppos       = 0;
 
269
  save_track   = 1;
 
270
  thiscd.trk   = NULL;
 
271
  thiscd.lists = NULL;
 
272
  tottime      = tmptime;
 
273
} // initWorkMan()
 
274
 
 
275
 
 
276
/**
 
277
 * Init CD-ROM and display
 
278
 */
 
279
void
 
280
KSCD::initCDROM()
 
281
{
 
282
  initimer->stop();
 
283
  kapp->processEvents();
 
284
  kapp->flushX();
 
285
 
 
286
  cdMode();
 
287
  volstartup = FALSE;
 
288
  if(cddrive_is_ok)
 
289
    volChanged(volume);
 
290
 
 
291
  timer->start(1000);
 
292
} // initCDROM
 
293
 
 
294
/**
 
295
 * Return fitting Helvetica font size for the 13 and 14 pixel widgets.
 
296
 * @return a reasonably small font size
 
297
 */
 
298
int
 
299
KSCD::smallPtSize()
 
300
{
 
301
  static int theSmallPtSize = 0;
 
302
 
 
303
  if ( theSmallPtSize != 0 )
 
304
    return theSmallPtSize;
 
305
 
 
306
  // Find a font that fits the 13 and 14 pixel widgets
 
307
  theSmallPtSize = 10;
 
308
  QFont fn( "Helvetica", theSmallPtSize, QFont::Bold );
 
309
  bool fits = false;
 
310
  while (!fits && theSmallPtSize > 1)
 
311
    {
 
312
      QFontMetrics metrics(fn);
 
313
      if(metrics.height() > 13)
 
314
        {
 
315
          --theSmallPtSize;
 
316
          fn.setPointSize(theSmallPtSize);
 
317
        } else {
 
318
          fits = true;
 
319
        }
 
320
    }
 
321
  return theSmallPtSize;
 
322
} // smallPtSize()
 
323
 
 
324
QPushButton *
 
325
KSCD::makeButton( int x, int y, int w, int h, const QString& n )
 
326
{
 
327
  QPushButton *pb = new QPushButton( n, this );
 
328
  pb->setGeometry( x, y, w, h );
 
329
  pb->setFocusPolicy ( QWidget::NoFocus );
 
330
  return pb;
 
331
} // makeButton
 
332
 
 
333
/**
 
334
 * drawPanel() constructs KSCD's main window.
 
335
 * This is oldstyle and needs to be redesigned.
 
336
 *
 
337
 * @author Bernd W�bben
 
338
 * @author Dirk F�rsterling
 
339
 */
 
340
void
 
341
KSCD::drawPanel()
 
342
{
 
343
  int ix = 0;
 
344
  int iy = 0;
 
345
  const int WIDTH = 90;
 
346
  const int HEIGHT = 27;
 
347
  const int SBARWIDTH = 220;
 
348
 
 
349
  aboutPB = makeButton( ix, iy, WIDTH, 2 * HEIGHT, i18n("About") );
 
350
 
 
351
  ix = 0;
 
352
  iy += 2 * HEIGHT;
 
353
 
 
354
  infoPB = makeButton( ix, iy, WIDTH/2, HEIGHT, "" );
 
355
  ejectPB = makeButton( ix + WIDTH/2, iy, WIDTH/2, HEIGHT, "" );
 
356
 
 
357
  iy += HEIGHT;
 
358
#if KSCDMAGIC
 
359
  dockPB = makeButton( ix, iy, WIDTH/2, HEIGHT, i18n("Quit") );
 
360
  magicPB = makeButton(ix+WIDTH/2, iy, WIDTH/2, HEIGHT, "" );
 
361
#else
 
362
  dockPB = makeButton( ix, iy, WIDTH, HEIGHT, i18n("Quit") );
 
363
#endif
 
364
  ix += WIDTH;
 
365
  iy = 0;
 
366
 
 
367
  backdrop = new QFrame(this);
 
368
  backdrop->setGeometry(ix,iy,SBARWIDTH -2, 2* HEIGHT + HEIGHT /2 -1);
 
369
  backdrop->setFocusPolicy ( QWidget::NoFocus );
 
370
 
 
371
  int D = 6;
 
372
 
 
373
  ix = WIDTH + 8;
 
374
  for (int u = 0; u<5;u++)
 
375
    {
 
376
      trackTimeLED[u] = new BW_LED_Number(this );
 
377
      trackTimeLED[u]->setGeometry( ix  + u*18, iy + D, 23 ,  30 );
 
378
      trackTimeLED[u]->setLEDoffColor(background_color);
 
379
      trackTimeLED[u]->setLEDColor(led_color,background_color);
 
380
    }
 
381
 
 
382
  QString zeros("--:--");
 
383
  setLEDs(zeros);
 
384
 
 
385
  artistlabel = new QLabel(this);
 
386
  artistlabel->setGeometry(WIDTH + 5, iy + 38 , SBARWIDTH -15, 13);
 
387
  artistlabel->setFont( QFont( "helvetica", smallPtSize(), QFont::Bold) );
 
388
  artistlabel->setAlignment( AlignLeft );
 
389
  artistlabel->clear();
 
390
 
 
391
  titlelabel = new QLabel(this);
 
392
  titlelabel->setGeometry(WIDTH + 5, iy + 50 , SBARWIDTH -15, 13);
 
393
  QFont ledfont( "Helvetica", smallPtSize()-2, QFont::Bold );
 
394
  titlelabel->setFont( ledfont );
 
395
  titlelabel->setAlignment( AlignLeft );
 
396
  titlelabel->clear();
 
397
 
 
398
  statuslabel = new QLabel(this);
 
399
  statuslabel->setGeometry(WIDTH + 110, iy  +D, 50, 14);
 
400
  statuslabel->setFont( ledfont );
 
401
  statuslabel->setAlignment( AlignLeft );
 
402
 
 
403
  queryled = new LedLamp(this);
 
404
  queryled->move(WIDTH + 200, iy  +D +1 );
 
405
  queryled->off();
 
406
  queryled->hide();
 
407
 
 
408
  loopled = new LedLamp(this, LedLamp::Loop);
 
409
  loopled->move(WIDTH + 200, iy  +D +18 );
 
410
  loopled->off();
 
411
 
 
412
  volumelabel = new QLabel(this);
 
413
  volumelabel->setGeometry(WIDTH + 110, iy + 14 + D, 50, 14);
 
414
  volumelabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold ) );
 
415
  volumelabel->setAlignment( AlignLeft );
 
416
  volumelabel->setText(i18n("Vol: --"));
 
417
 
 
418
  tracklabel = new QLabel(this);
 
419
  tracklabel->setGeometry(WIDTH + 168, iy + 14 +D, 30, 14);
 
420
  tracklabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold ) );
 
421
  tracklabel->setAlignment( AlignLeft );
 
422
  tracklabel->setText("--/--");
 
423
 
 
424
  totaltimelabel = new QLabel(this);
 
425
  totaltimelabel->setGeometry(WIDTH + 168, iy  +D, 50, 14);
 
426
  totaltimelabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold ) );
 
427
  totaltimelabel->setAlignment( AlignLeft );
 
428
  totaltimelabel->hide();
 
429
 
 
430
  ix = WIDTH;
 
431
  iy = HEIGHT + HEIGHT + HEIGHT/2;
 
432
 
 
433
  volSB = new QSlider( 0, 100, 5,  50, QSlider::Horizontal, this, "Slider" );
 
434
  volSB->setGeometry( ix, iy, SBARWIDTH, HEIGHT/2 );
 
435
  volSB->setFocusPolicy ( QWidget::NoFocus );
 
436
 
 
437
  iy += HEIGHT/2  +1 ;
 
438
  cddbbutton = new QPushButton( this );
 
439
  cddbbutton->setGeometry( ix , iy, SBARWIDTH/10 *2 , HEIGHT );
 
440
  cddbbutton->setFocusPolicy ( QWidget::NoFocus );
 
441
 
 
442
  ix += SBARWIDTH/10*2;
 
443
  shufflebutton = new QPushButton( this );
 
444
  shufflebutton->setGeometry( ix , iy, SBARWIDTH/10 *2  , HEIGHT );
 
445
  shufflebutton->setFocusPolicy ( QWidget::NoFocus );
 
446
 
 
447
  ix += SBARWIDTH/10*2;
 
448
 
 
449
  optionsbutton = new QPushButton( this );
 
450
  optionsbutton->setGeometry( ix, iy, SBARWIDTH/10 *2  , HEIGHT );
 
451
  optionsbutton->setFocusPolicy ( QWidget::NoFocus );
 
452
 
 
453
  ix = 0;
 
454
  iy += HEIGHT;
 
455
  songListCB = new QComboBox( this );
 
456
  songListCB->setGeometry( ix, iy, SBARWIDTH/10*18+6, HEIGHT );
 
457
  songListCB->setFont( QFont( "helvetica", smallPtSize() ) );
 
458
  songListCB->setFocusPolicy ( QWidget::NoFocus );
 
459
 
 
460
  iy = 0;
 
461
  ix = WIDTH + SBARWIDTH + 2;
 
462
  playPB = makeButton( ix, iy, WIDTH, HEIGHT*2, "Play/Pause" );
 
463
 
 
464
  iy += HEIGHT + HEIGHT;
 
465
  stopPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Stop" );
 
466
 
 
467
  ix += WIDTH / 2;
 
468
  replayPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Replay" );
 
469
 
 
470
  ix = WIDTH + SBARWIDTH/10*6;
 
471
  iy += HEIGHT;
 
472
  bwdPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Bwd" );
 
473
 
 
474
  ix += WIDTH / 2;
 
475
  fwdPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Fwd" );
 
476
 
 
477
  ix = WIDTH + SBARWIDTH + 2;
 
478
  prevPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Prev" );
 
479
 
 
480
  ix += WIDTH / 2;
 
481
  nextPB = makeButton( ix, iy, WIDTH / 2, HEIGHT, "Next" );
 
482
 
 
483
  this->adjustSize();
 
484
  this->setFixedSize(this->width(),this->height());
 
485
 
 
486
} // drawPanel
 
487
 
 
488
void
 
489
KSCD::loadBitmaps()
 
490
{
 
491
    QBitmap playBmp( playpause_width, playpause_height, playpause_bits,TRUE );
 
492
    QBitmap stopBmp( stop_width, stop_height, stop_bits, TRUE );
 
493
    QBitmap prevBmp( prevtrk_width, prevtrk_height, prevtrk_bits, TRUE );
 
494
    QBitmap nextBmp( nexttrk_width, nexttrk_height, nexttrk_bits, TRUE );
 
495
    QBitmap replayBmp( repeat_width, repeat_height, repeat_bits, TRUE );
 
496
    QBitmap fwdBmp( ff_width, ff_height, ff_bits, TRUE );
 
497
    QBitmap bwdBmp( rew_width, rew_height, rew_bits, TRUE );
 
498
    QBitmap ejectBmp( eject_width, eject_height, eject_bits, TRUE );
 
499
    QBitmap infoBmp( info_width, info_height,info_bits, TRUE );
 
500
    QBitmap dockBmp( poweroff_width, poweroff_height, poweroff_bits, TRUE );
 
501
#if KSCDMAGIC
 
502
    QBitmap magicBmp( magicxbm_width, magicxbm_height, magicxbm_bits, TRUE );
 
503
#endif
 
504
    QBitmap shuffleBmp( shuffle_width, shuffle_height, shuffle_bits, TRUE );
 
505
    QBitmap databaseBmp( db_width, db_height, db_bits, TRUE );
 
506
    QBitmap aboutBmp( logo_width, logo_height, logo_bits, TRUE );
 
507
    QBitmap optionsBmp( options_width, options_height, options_bits, TRUE );
 
508
 
 
509
    playPB->setPixmap( playBmp );
 
510
    stopPB->setPixmap( stopBmp );
 
511
    prevPB->setPixmap( prevBmp );
 
512
    nextPB->setPixmap( nextBmp );
 
513
    replayPB->setPixmap( replayBmp );
 
514
    fwdPB->setPixmap( fwdBmp );
 
515
    bwdPB->setPixmap( bwdBmp );
 
516
    ejectPB->setPixmap( ejectBmp );
 
517
    infoPB->setPixmap( infoBmp );
 
518
    dockPB->setPixmap( dockBmp );
 
519
#if KSCDMAGIC
 
520
    magicPB->setPixmap( magicBmp );
 
521
#endif
 
522
    // This is UGLY .... -- Bernd
 
523
    // dockPB->setFont(QFont("helvetica", 12, QFont::Bold));
 
524
    // dockPB->setText("DOCK");
 
525
 
 
526
    aboutPB->setPixmap( aboutBmp );
 
527
    shufflebutton->setPixmap( shuffleBmp );
 
528
    cddbbutton->setPixmap( databaseBmp );
 
529
    optionsbutton->setPixmap( optionsBmp );
 
530
} // loadBitmaps
 
531
 
 
532
 
 
533
void
 
534
KSCD::setupPopups()
 
535
{
 
536
    mainPopup   = new QPopupMenu ();
 
537
    perfPopup   = new QPopupMenu ();
 
538
    purchPopup   = new QPopupMenu ();
 
539
    infoPopup   = new QPopupMenu ();
 
540
 
 
541
    purchPopup->insertItem("CD Now", 0);
 
542
    purchPopup->insertItem("CD Universe", 1);
 
543
 
 
544
    perfPopup->insertItem("Tourdates.com", 0);
 
545
 
 
546
    infoPopup->insertItem("Ultimate Bandlist", 0);
 
547
    infoPopup->insertSeparator();
 
548
    infoPopup->insertItem("Deja News", 1);
 
549
    infoPopup->insertItem("Excite", 2);
 
550
    infoPopup->insertItem("HotBot", 3);
 
551
    infoPopup->insertItem("Info Seek", 4);
 
552
    infoPopup->insertItem("Lycos", 5);
 
553
    infoPopup->insertItem("Magellan", 6);
 
554
    infoPopup->insertItem("Yahoo!", 7);
 
555
 
 
556
    mainPopup->insertItem (i18n("Performances"), perfPopup);
 
557
    connect( perfPopup, SIGNAL(activated(int)), SLOT(performances(int)) );
 
558
 
 
559
    mainPopup->insertItem (i18n("Purchases"), purchPopup);
 
560
    connect( purchPopup, SIGNAL(activated(int)), SLOT(purchases(int)) );
 
561
 
 
562
    mainPopup->insertItem (i18n("Information"), infoPopup);
 
563
 
 
564
#if KSCDMAGIC
 
565
    mainPopup->insertSeparator(-1);
 
566
    mainPopup->insertItem (i18n("KSCD Magic"));
 
567
    connect( mainPopup, SIGNAL(activated(int)), SLOT(magicslot(int)) );
 
568
#endif
 
569
 
 
570
    connect( infoPopup, SIGNAL(activated(int)), SLOT(information(int)) );
 
571
    connect( infoPB, SIGNAL(clicked()), SLOT(showPopup()) );
 
572
} // setupPopups
 
573
 
 
574
void
 
575
KSCD::showPopup()
 
576
{
 
577
    QPoint point = this->mapToGlobal (QPoint(0,0));
 
578
 
 
579
    if(mainPopup)
 
580
        mainPopup->popup(point);
 
581
 
 
582
} // showPopup
 
583
 
 
584
void
 
585
KSCD::setToolTips()
 
586
{
 
587
    if(tooltips)
 
588
    {
 
589
        QToolTip::add( playPB,          i18n("Play/Pause") );
 
590
        QToolTip::add( stopPB,          i18n("Stop") );
 
591
        QToolTip::add( replayPB,        i18n("Loop") );
 
592
        QToolTip::add( songListCB,      i18n("Track Selection") );
 
593
        QToolTip::add( fwdPB,           i18n("30 Secs Forward") );
 
594
        QToolTip::add( bwdPB,           i18n("30 Secs Backward") );
 
595
        QToolTip::add( nextPB,          i18n("Next Track") );
 
596
        QToolTip::add( prevPB,          i18n("Previous Track") );
 
597
        QToolTip::add( dockPB,          i18n("Quit Kscd") );
 
598
#if KSCDMAGIC
 
599
        QToolTip::add( magicPB,         i18n("Run Kscd Magic") );
 
600
#endif
 
601
        QToolTip::add( aboutPB,         i18n("Cycle Time Display") );
 
602
        QToolTip::add( optionsbutton,   i18n("Configure Kscd") );
 
603
        QToolTip::add( ejectPB,         i18n("Eject CD") );
 
604
        QToolTip::add( infoPB,          i18n("The Artist on the Web") );
 
605
        if (!randomonce)
 
606
            QToolTip::add( shufflebutton,         i18n("Random Play") );
 
607
        else
 
608
            QToolTip::add( shufflebutton,         i18n("Shuffle Play") );
 
609
 
 
610
        QToolTip::add( cddbbutton,      i18n("freedb Dialog") );
 
611
        QToolTip::add( volSB,           i18n("CD Volume Control") );
 
612
    } else {
 
613
        QToolTip::remove( playPB);
 
614
        QToolTip::remove( stopPB);
 
615
        QToolTip::remove( replayPB);
 
616
        QToolTip::remove( songListCB);
 
617
        QToolTip::remove( fwdPB );
 
618
        QToolTip::remove( bwdPB);
 
619
        QToolTip::remove( nextPB );
 
620
        QToolTip::remove( prevPB );
 
621
        QToolTip::remove( dockPB );
 
622
#if KSCDMAGIC
 
623
        QToolTip::remove( magicPB );
 
624
#endif
 
625
        QToolTip::remove( aboutPB );
 
626
        QToolTip::remove( optionsbutton );
 
627
        QToolTip::remove( ejectPB );
 
628
        QToolTip::remove( infoPB );
 
629
        QToolTip::remove( cddbbutton );
 
630
        QToolTip::remove( shufflebutton );
 
631
        QToolTip::remove( volSB );
 
632
    }
 
633
} // setToolTips
 
634
 
 
635
void
 
636
KSCD::cleanUp()
 
637
{
 
638
    if (thiscd.trk != NULL)
 
639
    {
 
640
        delete thiscd.trk;
 
641
        thiscd.trk = 0L;
 
642
    }
 
643
    signal (SIGINT, SIG_DFL);
 
644
    if(magicproc)
 
645
    {
 
646
        delete magicproc;
 
647
        magicproc = 0L;
 
648
    }
 
649
} // cleanUp()
 
650
 
 
651
void
 
652
KSCD::playClicked()
 
653
{
 
654
    qApp->processEvents();
 
655
    qApp->flushX();
 
656
 
 
657
 
 
658
    if(
 
659
#ifdef NEW_BSD_PLAYCLICKED
 
660
        cur_cdmode == WM_CDM_STOPPED || cur_cdmode == WM_CDM_UNKNOWN  || cur_cdmode == WM_CDM_BACK
 
661
#else
 
662
        cur_cdmode == WM_CDM_STOPPED || cur_cdmode == WM_CDM_UNKNOWN
 
663
#endif
 
664
        ){
 
665
 
 
666
        statuslabel->setText( i18n("Playing") );
 
667
        songListCB->clear();
 
668
        setLEDs( "00:00" );
 
669
 
 
670
        songListCB->clear();
 
671
        QStringList::Iterator it = tracktitlelist.begin();
 
672
        ++it;
 
673
        int i = 0;
 
674
        for ( ; it != tracktitlelist.end(); ++it )
 
675
        {
 
676
            i++;
 
677
            QString str = QString::fromLatin1("%1: %2")
 
678
                          .arg(QString::number(i).rightJustify(2, '0'))
 
679
                          .arg(*it);
 
680
            songListCB->insertItem( str );
 
681
        }
 
682
 
 
683
        // We don't know the rest, but we should still have entries
 
684
        for( ; i < cur_ntracks; i++)
 
685
        {
 
686
            songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), i+1) ) );
 
687
        }
 
688
 
 
689
        qApp->processEvents();
 
690
        qApp->flushX();
 
691
 
 
692
        if(!playlist.isEmpty())
 
693
        {
 
694
            if(playlistpointer >=(int) playlist.count())
 
695
                playlistpointer = 0;
 
696
            wm_cd_play (atoi((*playlist.at(playlistpointer)).ascii()), 0,
 
697
                        atoi((*playlist.at(playlistpointer)).ascii()) + 1);
 
698
            save_track = cur_track = atoi((*playlist.at(playlistpointer)).ascii());
 
699
        } else {
 
700
            wm_cd_play (save_track, 0, cur_ntracks + 1);
 
701
        }
 
702
    } else { // if (WM_CDM_STOPPED||UNKNOWN)
 
703
        if (cur_cdmode == WM_CDM_PLAYING || cur_cdmode == WM_CDM_PAUSED)
 
704
        {
 
705
 
 
706
            switch (cur_cdmode)
 
707
            {
 
708
                case WM_CDM_PLAYING:
 
709
                    statuslabel->setText( i18n("Pause") );
 
710
                    wm_cd_pause();
 
711
                    break;
 
712
                case WM_CDM_PAUSED:
 
713
                    if(randomplay)
 
714
                    {
 
715
                        if (randomonce)
 
716
                            statuslabel->setText( i18n("Shuffle") );
 
717
                        else
 
718
                            statuslabel->setText( i18n("Random") );
 
719
                    } else {
 
720
                        statuslabel->setText( i18n("Playing") );
 
721
                    }
 
722
                    wm_cd_pause();
 
723
                    break;
 
724
 
 
725
                default:
 
726
                    // next release: force "stop".
 
727
                    statuslabel->setText( i18n("Strange....") );
 
728
                    break;
 
729
            } // switch
 
730
            qApp->processEvents();
 
731
            qApp->flushX();
 
732
        } // if (PLAYING||PAUSED)
 
733
    } // if (WM_CDM_STOPPED||UNKNOWN) else
 
734
    cdMode();
 
735
} // playClicked()
 
736
 
 
737
void
 
738
KSCD::stopClicked()
 
739
{
 
740
    //    looping = FALSE;
 
741
    randomplay = FALSE;
 
742
    stoppedByUser = TRUE;
 
743
    statuslabel->setText(i18n("Stopped"));
 
744
    setLEDs("--:--");
 
745
    qApp->processEvents();
 
746
    qApp->flushX();
 
747
 
 
748
    save_track = cur_track = 1;
 
749
    playlistpointer = 0;
 
750
    wm_cd_stop ();
 
751
} // stopClicked()
 
752
 
 
753
void
 
754
KSCD::prevClicked()
 
755
{
 
756
    setLEDs("00:00");
 
757
    qApp->processEvents();
 
758
    qApp->flushX();
 
759
 
 
760
    if(!playlist.isEmpty())
 
761
    {
 
762
        playlistpointer--;
 
763
        if(playlistpointer < 0 )
 
764
        {
 
765
            playlistpointer = playlist.count() -1;
 
766
        }
 
767
        cur_track = atoi((*playlist.at(playlistpointer)).ascii());
 
768
    } else {
 
769
        // djoham@netscape.net suggested the real-world cd-player behaviour
 
770
        // of only jumping to the beginning of the current track if playing
 
771
        // advanced more than 2 seconds. I think that's good, but maybe I'll
 
772
        // make this configurable.
 
773
        if(!(cur_pos_rel > 2))
 
774
            cur_track--;
 
775
        if (cur_track < 1)
 
776
            cur_track = cur_ntracks;
 
777
    }
 
778
    if(randomplay)
 
779
    {
 
780
        wm_cd_play (cur_track, 0, cur_track + 1);
 
781
    } else {
 
782
        wm_cd_play (cur_track, 0, cur_ntracks + 1);
 
783
    }
 
784
} // prevClicked()
 
785
 
 
786
void
 
787
KSCD::nextClicked()
 
788
{
 
789
    setLEDs("00:00");
 
790
    qApp->processEvents();
 
791
    qApp->flushX();
 
792
 
 
793
    if(randomplay)
 
794
    {
 
795
        int j = randomtrack();
 
796
        if ( j < 0 )
 
797
            return;
 
798
        tracklabel->setText(formatTrack(j, cd->ntracks));
 
799
 
 
800
        if(j < (int)tracktitlelist.count())
 
801
        {
 
802
            setArtistAndTitle(tracktitlelist.first(),
 
803
                              *tracktitlelist.at(j));
 
804
        }
 
805
        qApp->processEvents();
 
806
        qApp->flushX();
 
807
 
 
808
        wm_cd_play( j, 0, j + 1 );
 
809
 
 
810
    } else if(!playlist.isEmpty()) {
 
811
        if(playlistpointer < (int)playlist.count() - 1)
 
812
            playlistpointer++;
 
813
        else
 
814
            playlistpointer = 0;
 
815
 
 
816
        wm_cd_play (atoi((*playlist.at(playlistpointer)).ascii()),
 
817
                    0, atoi((*playlist.at(playlistpointer)).ascii()) + 1);
 
818
        cur_track = atoi( (*playlist.at(playlistpointer)).ascii() );
 
819
    } else {
 
820
        if (cur_track == cur_ntracks)
 
821
            cur_track = 0;
 
822
        wm_cd_play (cur_track + 1, 0, cur_ntracks + 1);
 
823
    }
 
824
} // nextClicked()
 
825
 
 
826
void
 
827
KSCD::fwdClicked()
 
828
{
 
829
    qApp->processEvents();
 
830
    qApp->flushX();
 
831
 
 
832
    if (cur_cdmode == WM_CDM_PLAYING)
 
833
    {
 
834
        tmppos = cur_pos_rel + 30;
 
835
        if (tmppos < thiscd.trk[cur_track - 1].length)
 
836
        {
 
837
            if(randomplay || !playlist.isEmpty())
 
838
                wm_cd_play (cur_track, tmppos, cur_track + 1);
 
839
            else
 
840
                wm_cd_play (cur_track, tmppos, cur_ntracks + 1);
 
841
        }
 
842
    }
 
843
} // fwdClicked()
 
844
 
 
845
void
 
846
KSCD::bwdClicked()
 
847
{
 
848
    qApp->processEvents();
 
849
    qApp->flushX();
 
850
 
 
851
    if (cur_cdmode == WM_CDM_PLAYING)
 
852
    {
 
853
        tmppos = cur_pos_rel - 30;
 
854
        if(randomplay || !playlist.isEmpty())
 
855
            wm_cd_play (cur_track, tmppos > 0 ? tmppos : 0, cur_track + 1);
 
856
        else
 
857
            wm_cd_play (cur_track, tmppos > 0 ? tmppos : 0, cur_ntracks + 1);
 
858
    }
 
859
    cdMode();
 
860
} // bwdClicked()
 
861
 
 
862
void
 
863
KSCD::quitClicked()
 
864
{
 
865
    quitPending = true;
 
866
    randomplay = FALSE;
 
867
    statuslabel->clear();
 
868
    setLEDs( "--:--" );
 
869
 
 
870
    qApp->processEvents();
 
871
    qApp->flushX();
 
872
 
 
873
    if(stopexit)
 
874
        wm_cd_stop ();
 
875
 
 
876
    wm_cd_status();
 
877
    wm_cd_status();
 
878
 
 
879
    wm_free_cdtext();
 
880
 
 
881
    cleanUp();
 
882
    writeSettings();
 
883
    qApp->quit();
 
884
    //e->accept();
 
885
 
 
886
} // quitClicked()
 
887
 
 
888
 
 
889
void
 
890
KSCD::closeEvent( QCloseEvent *e )
 
891
{
 
892
    quitPending = true;
 
893
    randomplay = FALSE;
 
894
 
 
895
    statuslabel->clear();
 
896
 
 
897
    setLEDs( "--:--" );
 
898
 
 
899
    qApp->processEvents();
 
900
    qApp->flushX();
 
901
 
 
902
    if(stopexit)
 
903
        wm_cd_stop ();
 
904
 
 
905
    wm_cd_status();
 
906
    wm_cd_status();
 
907
    cleanUp();
 
908
    writeSettings();
 
909
    e->accept();
 
910
} // closeEvent
 
911
 
 
912
bool
 
913
KSCD::event( QEvent *e )
 
914
{
 
915
    return QWidget::event(e);
 
916
} // event
 
917
 
 
918
 
 
919
void
 
920
KSCD::loopOn()
 
921
{
 
922
    looping = true;
 
923
    loopled->on();
 
924
    loopled->show();
 
925
    qApp->processEvents();
 
926
    qApp->flushX();
 
927
} // loopOn;
 
928
 
 
929
void
 
930
KSCD::loopOff()
 
931
{
 
932
    looping = false;
 
933
    loopled->off();
 
934
    loopled->show();
 
935
    qApp->processEvents();
 
936
    qApp->flushX();
 
937
} // loopOff;
 
938
 
 
939
void
 
940
KSCD::loopClicked()
 
941
{
 
942
    //    randomplay = FALSE;
 
943
 
 
944
    if(looping)
 
945
    {
 
946
        loopOff();
 
947
    } else {
 
948
        loopOn();
 
949
    }
 
950
} // loopClicked
 
951
 
 
952
/**
 
953
 * Do everything needed if the user requested to eject the disc.
 
954
 *
 
955
 */
 
956
void
 
957
KSCD::ejectClicked()
 
958
{
 
959
    if(!cddrive_is_ok)
 
960
        return;
 
961
    if(!currentlyejected)
 
962
    {
 
963
            //      looping = FALSE;
 
964
            randomplay = FALSE;
 
965
            statuslabel->setText(i18n("Ejecting"));
 
966
            qApp->processEvents();
 
967
            qApp->flushX();
 
968
            setArtistAndTitle("", "");
 
969
            tracktitlelist.clear();
 
970
            extlist.clear();
 
971
 
 
972
            wm_cd_stop();
 
973
            //  timer->stop();
 
974
            /*
 
975
             * new checkmount goes here
 
976
             *
 
977
             */
 
978
            wm_cd_eject();
 
979
    } else {
 
980
            statuslabel->setText(i18n("Closing"));
 
981
            qApp->processEvents();
 
982
            qApp->flushX();
 
983
            have_new_cd = true;
 
984
            wm_cd_closetray();
 
985
    }
 
986
} // ejectClicked
 
987
 
 
988
void
 
989
KSCD::randomSelected()
 
990
{
 
991
    if(randomplay == TRUE)
 
992
    {
 
993
        randomplay = FALSE;
 
994
    }
 
995
    else
 
996
    {
 
997
        if( randomonce )
 
998
            statuslabel->setText(i18n("Shuffle"));
 
999
        else
 
1000
            statuslabel->setText(i18n("Random"));
 
1001
 
 
1002
        randomplay = TRUE;
 
1003
        if(tracktitlelist.count()==0)
 
1004
            return;
 
1005
        make_random_list(); /* koz: Build a unique, once, random list */
 
1006
        int j = randomtrack();
 
1007
        tracklabel->setText(formatTrack(j, cd->ntracks));
 
1008
        if(tracktitlelist.count()!=0 && j < (int)tracktitlelist.count())
 
1009
        {
 
1010
            setArtistAndTitle(tracktitlelist.first(),
 
1011
                              *tracktitlelist.at(j));
 
1012
        }
 
1013
        qApp->processEvents();
 
1014
        qApp->flushX();
 
1015
 
 
1016
        wm_cd_play( j, 0, j + 1 );
 
1017
        cur_track = j;
 
1018
    }
 
1019
} // randomSelected
 
1020
 
 
1021
/**
 
1022
 * A Track was selected for playback from the drop down box.
 
1023
 *
 
1024
 */
 
1025
void
 
1026
KSCD::trackSelected( int trk )
 
1027
{
 
1028
    randomplay = false;
 
1029
    tracklabel->setText( formatTrack( trk + 1, cd->ntracks ) );
 
1030
 
 
1031
    if(trk+1 < (int)tracktitlelist.count())
 
1032
    {
 
1033
        setArtistAndTitle(tracktitlelist.first(),
 
1034
                          *tracktitlelist.at(trk+1));
 
1035
    }
 
1036
 
 
1037
    setLEDs("00:00");
 
1038
    qApp->processEvents();
 
1039
    qApp->flushX();
 
1040
 
 
1041
    cur_track = trk + 1;
 
1042
    //  pause_cd();
 
1043
    wm_cd_play( cur_track, 0, cur_ntracks + 1 );
 
1044
} // trackSelected
 
1045
 
 
1046
void
 
1047
KSCD::aboutClicked()
 
1048
{
 
1049
    QString server_copy;
 
1050
    server_copy = current_server;
 
1051
 
 
1052
    QTabDialog * tabdialog;
 
1053
 
 
1054
    tabdialog = new QTabDialog(this,"tabdialog",TRUE);
 
1055
    tabdialog->setCaption( i18n("kscd Configuraton") );
 
1056
    tabdialog->resize(559, 512);
 
1057
    tabdialog->setCancelButton( i18n("Cancel") );
 
1058
 
 
1059
    QWidget *about = new QWidget(tabdialog,"about");
 
1060
    QBoxLayout * lay1 = new QVBoxLayout ( about, 10 );
 
1061
    QGroupBox *box = new QGroupBox(about,"box");
 
1062
    lay1->addWidget ( box );
 
1063
    QBoxLayout * lay2 = new QHBoxLayout ( box, 15 );
 
1064
 
 
1065
    QPixmap pm = UserIcon("kscdlogo");
 
1066
    QLabel *logo = new QLabel(box);
 
1067
    logo->setPixmap(pm);
 
1068
    logo->setFixedSize(pm.width(), pm.height());
 
1069
    lay2->addWidget ( logo );
 
1070
 
 
1071
    QString labelstring;
 
1072
    labelstring = i18n("kscd %1\n").arg(KSCDVERSION);
 
1073
    labelstring += i18n(
 
1074
        "Copyright (c) 1997-2001 \nBernd Johannes Wuebben <wuebben@kde.org>\n"
 
1075
        "Copyright (c) 1999-2001 \nDirk Försterling <milliByte@gmx.net>\n"
 
1076
        "   (current Maintainer)\n\n"
 
1077
        "Kscd is based in part on WorkMan,\n"
 
1078
        "Copyright (c) 1991-1996 Steven Grimm\n"
 
1079
        "Copyright (c) 1996-2001 Dirk Försterling <milliByte@gmx.net>\n\n"
 
1080
        "Special thanks to freedb.org for "
 
1081
        "providing a free CDDB-like "
 
1082
        "CD database."
 
1083
        "Visit http://www.freedb.org/ for "
 
1084
        "more information on freedb.\n\n"
 
1085
        );
 
1086
 
 
1087
#if KSCDMAGIC
 
1088
    labelstring += i18n(
 
1089
        "KSCD Magic based on Synaesthesia by "
 
1090
        "Paul Harrison <pfh@yoyo.cc.monash.edu.au>\n\n");
 
1091
#endif
 
1092
    labelstring += i18n(
 
1093
        "Thanks to Vadim Zaliva <lord@crocodile.org>\n"
 
1094
        "for his work on the http proxy code.\n\n") ;
 
1095
 
 
1096
 
 
1097
    QLabel  *label = new QLabel(box,"label");
 
1098
    label->setAlignment(AlignLeft|WordBreak|ExpandTabs);
 
1099
    label->setText(labelstring);
 
1100
    lay2->addWidget ( label );
 
1101
 
 
1102
    ConfigDlg* dlg;
 
1103
    struct configstruct config;
 
1104
    config.background_color = background_color;
 
1105
    config.led_color = led_color;
 
1106
    config.tooltips = tooltips;
 
1107
    config.cd_device = QFile::decodeName(cd_device);
 
1108
    config.browsercmd = browsercmd;
 
1109
    config.use_kfm    = use_kfm;
 
1110
    config.docking    = docking;
 
1111
    config.autoplay   = autoplay;
 
1112
    config.stopexit = stopexit;
 
1113
    config.ejectonfinish = ejectonfinish;
 
1114
    config.randomonce = randomonce;
 
1115
 
 
1116
    dlg = new ConfigDlg(tabdialog,&config,"configdialg");
 
1117
 
 
1118
    setup = new CDDBSetup(tabdialog,"cddbsetupdialog");
 
1119
    connect(setup,SIGNAL(updateCDDBServers()),this,SLOT(getCDDBservers()));
 
1120
    connect(setup,SIGNAL(updateCurrentServer()),this,SLOT(updateCurrentCDDBServer()));
 
1121
    setup->insertData(cddbserverlist,
 
1122
                      cddbsubmitlist,
 
1123
                      cddbbasedir,
 
1124
                      submitaddress,
 
1125
                      current_server,
 
1126
                      cddb_auto_enabled,
 
1127
                      cddb_remote_enabled,
 
1128
                      cddb.getTimeout(),
 
1129
                      cddb.useHTTPProxy(),
 
1130
                      cddb.getHTTPProxyHost(),
 
1131
                      cddb.getHTTPProxyPort()
 
1132
        );
 
1133
 
 
1134
    MGConfigDlg* mgdlg;
 
1135
    struct mgconfigstruct mgconfig;
 
1136
    mgconfig.width = magic_width;
 
1137
    mgconfig.height = magic_height;
 
1138
    mgconfig.brightness = magic_brightness;
 
1139
    mgconfig.pointsAreDiamonds = magic_pointsAreDiamonds;
 
1140
    mgdlg = new MGConfigDlg(tabdialog,&mgconfig,"mgconfigdialg");
 
1141
 
 
1142
    smtpconfig = new SMTPConfig(tabdialog, "smtpconfig", &smtpConfigData);
 
1143
 
 
1144
    tabdialog->addTab(setup,"freedb");
 
1145
    tabdialog->addTab(smtpconfig, i18n("SMTP Setup"));
 
1146
    tabdialog->addTab(dlg,i18n("Kscd Options"));
 
1147
#if KSCDMAGIC
 
1148
    tabdialog->addTab(mgdlg,i18n("Kscd Magic"));
 
1149
#endif
 
1150
    tabdialog->addTab(about,i18n("About"));
 
1151
 
 
1152
 
 
1153
 
 
1154
    if(tabdialog->exec() == QDialog::Accepted)
 
1155
    {
 
1156
        smtpconfig->commitData();
 
1157
        background_color = dlg->getData()->background_color;
 
1158
        led_color = dlg->getData()->led_color;
 
1159
        tooltips = dlg->getData()->tooltips;
 
1160
 
 
1161
        browsercmd = dlg->getData()->browsercmd;
 
1162
        use_kfm = dlg->getData()->use_kfm;
 
1163
        docking = dlg->getData()->docking;
 
1164
        autoplay = dlg->getData()->autoplay;
 
1165
        stopexit = dlg->getData()->stopexit;
 
1166
        ejectonfinish = dlg->getData()->ejectonfinish;
 
1167
        randomonce = dlg->getData()->randomonce;
 
1168
 
 
1169
        if( (QString)cd_device != dlg->getData()->cd_device)
 
1170
        {
 
1171
            cd_device_str = dlg->getData()->cd_device;
 
1172
            cd_device = (char *)qstrdup(QFile::encodeName(cd_device_str));
 
1173
            cur_cdmode = WM_CDM_DEVICECHANGED;
 
1174
            device_change = true;
 
1175
            setArtistAndTitle("", "");
 
1176
            tracktitlelist.clear();
 
1177
            extlist.clear();
 
1178
            songListCB->clear();
 
1179
            cdMode();
 
1180
        }
 
1181
        cddrive_is_ok = true;
 
1182
 
 
1183
        magic_width = mgdlg->getData()->width;
 
1184
        magic_height = mgdlg->getData()->height;
 
1185
        magic_brightness = mgdlg->getData()->brightness;
 
1186
        magic_pointsAreDiamonds = mgdlg->getData()->pointsAreDiamonds;
 
1187
 
 
1188
        bool cddb_proxy_enabled;
 
1189
        QString cddb_proxy_host;
 
1190
        unsigned short int cddb_proxy_port;
 
1191
        unsigned short int cddb_timeout;
 
1192
 
 
1193
        setup->getData(cddbserverlist,
 
1194
                       cddbsubmitlist,
 
1195
                       cddbbasedir,
 
1196
                       submitaddress,
 
1197
                       current_server,
 
1198
                       cddb_auto_enabled,
 
1199
                       cddb_remote_enabled,
 
1200
                       cddb_timeout,
 
1201
                       cddb_proxy_enabled,
 
1202
                       cddb_proxy_host,
 
1203
                       cddb_proxy_port
 
1204
            );
 
1205
        cddb.setTimeout(cddb_timeout);
 
1206
        cddb.setHTTPProxy(cddb_proxy_host,cddb_proxy_port);
 
1207
        cddb.useHTTPProxy(cddb_proxy_enabled);
 
1208
 
 
1209
        setColors();
 
1210
        setToolTips();
 
1211
 
 
1212
        if(docking)
 
1213
            dock_widget->show();
 
1214
        else
 
1215
            dock_widget->hide();
 
1216
 
 
1217
    } else {
 
1218
        // reset the current server in case we played with it ...
 
1219
        current_server = server_copy;
 
1220
        kdDebug() << "RESETTING SERVER TO: " << current_server << "\n" << endl;
 
1221
    }
 
1222
 
 
1223
    disconnect(setup,SIGNAL(updateCDDBServers()),this,SLOT(getCDDBservers()));
 
1224
    disconnect(setup,SIGNAL(updateCurrentServer()),this,SLOT(updateCurrentCDDBServer()));
 
1225
 
 
1226
    delete dlg;
 
1227
    dlg = 0L;
 
1228
    delete setup;
 
1229
    setup = 0L;
 
1230
    delete smtpconfig;
 
1231
    smtpconfig = 0L;
 
1232
    delete about;
 
1233
    delete tabdialog;
 
1234
 
 
1235
} // aboutClicked()
 
1236
 
 
1237
void
 
1238
KSCD::updateCurrentCDDBServer()
 
1239
{
 
1240
    if(setup)
 
1241
    {
 
1242
        setup->getCurrentServer(current_server);
 
1243
        kdDebug() << "SET SERVER TO: " << current_server << "\n" << endl;
 
1244
    }
 
1245
} // updateCurrentCDDBServer
 
1246
 
 
1247
void
 
1248
KSCD::volChanged( int vol )
 
1249
{
 
1250
    if(volstartup)
 
1251
        return;
 
1252
 
 
1253
    QString str;
 
1254
    str = QString::fromUtf8( QCString().sprintf( i18n("Vol: %02d%%").utf8(),vol) );
 
1255
    volumelabel->setText(str);
 
1256
    cd_volume(vol, 10, 100); // 10 -> right == left balance
 
1257
    volume = vol;
 
1258
} // volChanged
 
1259
 
 
1260
 
 
1261
int
 
1262
KSCD::randomtrack()
 
1263
{
 
1264
    /* koz: 15/01/00. Check to see if we want to do a randomonce. If so */
 
1265
    /* we execute the first set of statements. Else we execute the second */
 
1266
    /* set, the original code.  */
 
1267
    if( randomonce )
 
1268
    {
 
1269
        if( !playlist.isEmpty() )
 
1270
        {
 
1271
            /* Check to see if we are at the end of the list */
 
1272
            if( (unsigned int)random_current >= playlist.count() )
 
1273
            {
 
1274
                if( !looping )
 
1275
                {
 
1276
                    stopClicked();
 
1277
                    return -1;
 
1278
                } else {
 
1279
                    random_current=0;
 
1280
                }
 
1281
            }
 
1282
            int j = random_list[random_current++];
 
1283
            playlistpointer = j;
 
1284
            return atoi( (*playlist.at(j)).ascii() );
 
1285
        } else { // playlist.count > 0
 
1286
            if( random_current >= cur_ntracks )
 
1287
            {
 
1288
                if( !looping )
 
1289
                {
 
1290
                    stopClicked();
 
1291
                    return -1;
 
1292
                } else {
 
1293
                    random_current = 0;
 
1294
                }
 
1295
            }
 
1296
            return( random_list[random_current++] );
 
1297
        } // playlist.count > 0
 
1298
    } // randomonce
 
1299
 
 
1300
    if( !playlist.isEmpty() )
 
1301
    {
 
1302
        int j;
 
1303
        j = (int) randSequence.getLong(playlist.count());
 
1304
        playlistpointer = j;
 
1305
        return atoi( (*playlist.at(j)).ascii() );
 
1306
    } else {
 
1307
        int j;
 
1308
        j = (cur_ntracks == 0) ? 0 : (1 + (int) randSequence.getLong(cur_ntracks));
 
1309
        return j;
 
1310
    }
 
1311
} // randomtrack
 
1312
 
 
1313
/*
 
1314
 * cdMode
 
1315
 *
 
1316
 * - 'No disc' handling is missing
 
1317
 * - Data discs not recognized as data discs.
 
1318
 *
 
1319
 */
 
1320
void
 
1321
KSCD::cdMode()
 
1322
{
 
1323
 
 
1324
  static char *p = new char[10];
 
1325
  static bool damn = TRUE;
 
1326
  QString str;
 
1327
 
 
1328
  sss = wm_cd_status();
 
1329
  if( sss == 2 )
 
1330
      have_new_cd = true;
 
1331
 
 
1332
  if(sss < 0)
 
1333
  {
 
1334
        if(cddrive_is_ok && (sss != WM_ERR_SCSI_INQUIRY_FAILED))
 
1335
        {
 
1336
            statuslabel->setText( i18n("Error") );
 
1337
            cddrive_is_ok = false;
 
1338
            QString errstring =
 
1339
                i18n("CDROM read or access error (or no audio disc in drive).\n"\
 
1340
                     "Please make sure you have access permissions to:\n%1")
 
1341
                .arg(cd_device);
 
1342
            KMessageBox::error(this, errstring, i18n("Error"));
 
1343
        }
 
1344
        return;
 
1345
    }
 
1346
    cddrive_is_ok = true; // cd drive ok
 
1347
 
 
1348
    if(cur_cdmode == WM_CDM_EJECTED)
 
1349
        currentlyejected = true;
 
1350
    else
 
1351
        currentlyejected = false;
 
1352
 
 
1353
    if( device_change == true )
 
1354
      {
 
1355
        device_change = false;
 
1356
        cur_cdmode = WM_CDM_STOPPED;
 
1357
        damn = false;
 
1358
      }
 
1359
 
 
1360
    switch (cur_cdmode) {
 
1361
        case WM_CDM_UNKNOWN:
 
1362
            cur_track = save_track = 1;
 
1363
            statuslabel->setText( "" ); // TODO how should I properly handle this
 
1364
            damn = TRUE;
 
1365
            break;
 
1366
 
 
1367
        case WM_CDM_TRACK_DONE: // == WM_CDM_BACK
 
1368
            if( randomplay )
 
1369
            {
 
1370
                int j = randomtrack();
 
1371
                wm_cd_play( j, 0, j + 1 );
 
1372
 
 
1373
            }
 
1374
            else if (playlist.count() > 0)
 
1375
            {
 
1376
                if(playlistpointer < (int)playlist.count() - 1)
 
1377
                    playlistpointer++;
 
1378
                else
 
1379
                    playlistpointer = 0;
 
1380
                wm_cd_play(atoi( (*playlist.at(playlistpointer)).ascii() ),0,atoi((*playlist.at(playlistpointer)).ascii())+1);
 
1381
            }
 
1382
            else if ( looping )
 
1383
            {
 
1384
                if (cur_track == cur_ntracks)
 
1385
                {
 
1386
                    cur_track = 0;
 
1387
                    wm_cd_play (1, 0, cur_ntracks + 1);
 
1388
                }
 
1389
 
 
1390
            } else {
 
1391
                cur_track = save_track = 1;
 
1392
                statuslabel->clear(); // TODO how should I properly handle this
 
1393
                damn = TRUE;
 
1394
            }
 
1395
            break;
 
1396
 
 
1397
        case WM_CDM_PLAYING:
 
1398
            playtime ();
 
1399
            if(randomplay)
 
1400
                if(randomonce)
 
1401
                {
 
1402
                    statuslabel->setText( i18n("Shuffle") );
 
1403
                } else {
 
1404
                    statuslabel->setText( i18n("Random") );
 
1405
                }
 
1406
            //        else if(looping)
 
1407
            //            statuslabel->setText( i18n("Loop") );
 
1408
            else
 
1409
                statuslabel->setText( i18n("Playing") );
 
1410
 
 
1411
            sprintf( p, "%02d  ", cur_track );
 
1412
            if (songListCB->count() == 0)
 
1413
            {
 
1414
                // we are in here when we start kscd and
 
1415
                // the cdplayer is already playing.
 
1416
                int i = 0;
 
1417
                songListCB->clear();
 
1418
                QStringList::Iterator it = tracktitlelist.begin();
 
1419
                ++it;
 
1420
                for ( ; it != tracktitlelist.end(); ++it )
 
1421
                {
 
1422
                    i++;
 
1423
                    songListCB->insertItem( QString("").sprintf("%02d: %s", i, (*it).utf8().data()));
 
1424
                }
 
1425
                for(; i < cur_ntracks; i++)
 
1426
                {
 
1427
                    songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), i+1)) );
 
1428
                }
 
1429
 
 
1430
//            for (int i = 0; i < cur_ntracks; i++){
 
1431
//                songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("Track %02d").utf8(),i + 1 ) ) );
 
1432
//            }
 
1433
                songListCB->setCurrentItem( cur_track - 1 );
 
1434
                have_new_cd = false;
 
1435
                get_cddb_info(false); // false == do not update dialog if open
 
1436
            } else {
 
1437
                songListCB->setCurrentItem( cur_track - 1 );
 
1438
            }
 
1439
            tracklabel->setText( formatTrack(cur_track, cd->ntracks) );
 
1440
 
 
1441
            if((cur_track < (int)tracktitlelist.count()) && (cur_track >= 0))
 
1442
            {
 
1443
                setArtistAndTitle(tracktitlelist.first(),
 
1444
                                  *tracktitlelist.at(cur_track));
 
1445
            }
 
1446
 
 
1447
            setLEDs( tmptime );
 
1448
            damn = TRUE;
 
1449
            stoppedByUser = false;
 
1450
            break;
 
1451
 
 
1452
        case WM_CDM_FORWARD:
 
1453
            break;
 
1454
 
 
1455
        case WM_CDM_PAUSED:
 
1456
            statuslabel->setText( i18n("Pause") );
 
1457
            damn = TRUE;
 
1458
            break;
 
1459
 
 
1460
        case WM_CDM_STOPPED:
 
1461
            if (damn) {
 
1462
                if(ejectonfinish && !stoppedByUser){
 
1463
                    stoppedByUser = true;
 
1464
                    ejectClicked();
 
1465
                    break;
 
1466
                }
 
1467
                statuslabel->setText( i18n("Ready") );
 
1468
                setLEDs( "--:--" );
 
1469
                songListCB->clear();
 
1470
 
 
1471
                int i = 0;
 
1472
                songListCB->clear();
 
1473
                QStringList::Iterator it = tracktitlelist.begin();
 
1474
                ++it;
 
1475
                for ( ; it != tracktitlelist.end(); ++it )
 
1476
                {
 
1477
                    i++;
 
1478
                    songListCB->insertItem( QString().sprintf("%02d: %s", i, (*it).utf8().data()));
 
1479
                }
 
1480
                for(; i < cur_ntracks; i++){
 
1481
                    songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), i+1)) );
 
1482
                }
 
1483
 
 
1484
//            for (i = 0; i < cur_ntracks; i++)
 
1485
//                songListCB->insertItem( QString( 0 ).sprintf( i18n("Track %02d"), i + 1 ) );
 
1486
 
 
1487
                int w = ((cur_track >= 0) ? cur_track : 1);
 
1488
 
 
1489
                tracklabel->setText( formatTrack( cur_track >= 0 ? cur_track : 1, cd->ntracks) );
 
1490
 
 
1491
                if( w < (int)tracktitlelist.count()){
 
1492
                    setArtistAndTitle(tracktitlelist.first(),
 
1493
                                      *tracktitlelist.at( w ));
 
1494
                }
 
1495
            }
 
1496
            damn = FALSE;
 
1497
            if(have_new_cd){
 
1498
 
 
1499
                //      timer->stop();
 
1500
                have_new_cd = false;
 
1501
                // timer must be restarted when we are doen
 
1502
                // with getting the cddb info
 
1503
                get_cddb_info(false); // false == do not update dialog if open
 
1504
                if(autoplay && ejectedBefore)
 
1505
                    playClicked();
 
1506
            }
 
1507
 
 
1508
            break;
 
1509
 
 
1510
        case WM_CDM_EJECTED:
 
1511
            statuslabel->setText( i18n("Ejected") );
 
1512
                        setArtistAndTitle("", "");
 
1513
                        tracktitlelist.clear();
 
1514
                        extlist.clear();
 
1515
                        songListCB->clear();
 
1516
            setLEDs( "--:--" );
 
1517
            tracklabel->setText( "--/--" );
 
1518
            setArtistAndTitle("", "");
 
1519
            totaltimelabel->clear();
 
1520
            totaltimelabel->lower();
 
1521
            damn = TRUE;
 
1522
            ejectedBefore = TRUE;
 
1523
 
 
1524
            break;
 
1525
    }
 
1526
} /* cdMode */
 
1527
 
 
1528
void
 
1529
KSCD::setLEDs(const QString& symbols)
 
1530
{
 
1531
 
 
1532
    // nLEDs->setText(symbols);
 
1533
 
 
1534
    if(symbols.length() < 5){
 
1535
        return;
 
1536
    }
 
1537
 
 
1538
    for(int i=0;i<5;i++){
 
1539
        trackTimeLED[i]->display(symbols[i].latin1());
 
1540
    }
 
1541
}
 
1542
 
 
1543
 
 
1544
void
 
1545
KSCD::setColors()
 
1546
{
 
1547
    backdrop->setBackgroundColor(background_color);
 
1548
 
 
1549
    QColorGroup colgrp( led_color, background_color, led_color,led_color , led_color,
 
1550
                        led_color, white );
 
1551
 
 
1552
    titlelabel ->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1553
    artistlabel->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1554
    volumelabel->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1555
    statuslabel->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1556
    tracklabel ->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1557
    totaltimelabel->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1558
    // nLEDs->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1559
 
 
1560
 
 
1561
    queryled->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1562
    loopled->setPalette( QPalette(colgrp,colgrp,colgrp) );
 
1563
 
 
1564
    for (int u = 0; u< 5;u++){
 
1565
        trackTimeLED[u]->setLEDoffColor(background_color);
 
1566
        trackTimeLED[u]->setLEDColor(led_color,background_color);
 
1567
    }
 
1568
 
 
1569
    titlelabel ->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1570
    artistlabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1571
    volumelabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1572
    statuslabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1573
    tracklabel ->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1574
    totaltimelabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1575
    artistlabel->setFont( QFont( "Helvetica", smallPtSize(), QFont::Bold) );
 
1576
 
 
1577
}
 
1578
 
 
1579
 
 
1580
void
 
1581
KSCD::readSettings()
 
1582
{
 
1583
    config = kapp->config();
 
1584
 
 
1585
    config->setGroup("GENERAL");
 
1586
    volume     = config->readNumEntry("Volume",40);
 
1587
    tooltips   = config->readBoolEntry("ToolTips", true);
 
1588
    randomplay = config->readBoolEntry("RandomPlay", false);
 
1589
    use_kfm    = config->readBoolEntry("USEKFM", true);
 
1590
    docking    = config->readBoolEntry("DOCKING", true);
 
1591
    autoplay = config->readBoolEntry("AUTOPLAY", false);
 
1592
    stopexit = config->readBoolEntry("STOPEXIT", true);
 
1593
    ejectonfinish = config->readBoolEntry("EJECTONFINISH", false);
 
1594
    randomonce = (bool)config->readBoolEntry("RANDOMONCE",true);
 
1595
    looping    = config->readBoolEntry("Looping",false);
 
1596
    browsercmd = config->readEntry("CustomBrowserCmd","kfmclient openURL %s");
 
1597
 
 
1598
 
 
1599
#ifdef DEFAULT_CD_DEVICE
 
1600
 
 
1601
    // sun ultrix etc have a canonical cd rom device specified in the
 
1602
    // respective plat_xxx.c file. On those platforms you need nnot
 
1603
    // specify the cd rom device and DEFAULT_CD_DEVICE is not defined
 
1604
    // in config.h
 
1605
 
 
1606
    cd_device_str = config->readEntry("CDDevice",DEFAULT_CD_DEVICE);
 
1607
    // FIXME
 
1608
    cd_device = (char *)qstrdup(QFile::encodeName(cd_device_str));
 
1609
 
 
1610
#endif
 
1611
 
 
1612
 
 
1613
    QColor defaultback = black;
 
1614
    QColor defaultled = QColor(226,224,255);
 
1615
    background_color = config->readColorEntry("BackColor",&defaultback);
 
1616
    led_color = config->readColorEntry("LEDColor",&defaultled);
 
1617
 
 
1618
    config->setGroup("MAGIC");
 
1619
    magic_width      = config->readNumEntry("magicwidth",320);
 
1620
    magic_height     = config->readNumEntry("magicheight",200);
 
1621
    magic_brightness = config->readNumEntry("magicbrightness", 3);
 
1622
    magic_pointsAreDiamonds = config->readBoolEntry("magicPointsAreDiamonds", false);
 
1623
 
 
1624
    config->setGroup("SMTP");
 
1625
    smtpConfigData.enabled = config->readBoolEntry("enabled", true);
 
1626
    smtpConfigData.mailProfile = config->readEntry("mailProfile", i18n("Default"));
 
1627
 
 
1628
    // Same as follows happens in smtpconfig.cpp. Try to remove one.
 
1629
    KEMailSettings *kes = new KEMailSettings();
 
1630
    kes->setProfile( smtpConfigData.mailProfile );
 
1631
    smtpConfigData.serverHost = kes->getSetting( KEMailSettings::OutServer );
 
1632
    smtpConfigData.serverPort = "25";
 
1633
    smtpConfigData.senderAddress = kes->getSetting( KEMailSettings::EmailAddress );
 
1634
    smtpConfigData.senderReplyTo = kes->getSetting( KEMailSettings::ReplyToAddress );
 
1635
    // Don't accept obviously bogus settings.
 
1636
    if( (smtpConfigData.serverHost == "") || (!smtpConfigData.senderAddress.contains("@")))
 
1637
    {
 
1638
        smtpConfigData.enabled = false;
 
1639
    }
 
1640
 
 
1641
    config->setGroup("CDDB");
 
1642
 
 
1643
    cddb.setTimeout(config->readNumEntry("CDDBTimeout",60));
 
1644
    cddb_auto_enabled = config->readBoolEntry("CDDBLocalAutoSaveEnabled",false);
 
1645
    cddbbasedir = config->readEntry("LocalBaseDir");
 
1646
    if (cddbbasedir.isEmpty())
 
1647
        cddbbasedir = KGlobal::dirs()->resourceDirs("cddb").last();
 
1648
    KGlobal::dirs()->addResourceDir("cddb", cddbbasedir);
 
1649
 
 
1650
// Set this to false by default. Look at the settings dialog source code
 
1651
// for the reason. - Juraj.
 
1652
    cddb_remote_enabled = config->readBoolEntry("CDDBRemoteEnabled",
 
1653
                                                false);
 
1654
    cddb.useHTTPProxy(config->readBoolEntry("CDDBHTTPProxyEnabled",
 
1655
                                            KProtocolManager::useProxy()));
 
1656
    KURL proxyURL;
 
1657
    QString proxyHost;
 
1658
    int proxyPort;
 
1659
    QString proxy = KProtocolManager::httpProxy();
 
1660
    if( !proxy.isEmpty() )
 
1661
      {
 
1662
        proxyURL = proxy;
 
1663
        proxyHost = proxyURL.host();
 
1664
        proxyPort = proxyURL.port();
 
1665
      } else {
 
1666
        proxyHost = "";
 
1667
        proxyPort = 0;
 
1668
        cddb.useHTTPProxy(false);
 
1669
      }
 
1670
    cddb.setHTTPProxy(config->readEntry("HTTPProxyHost",proxyHost),
 
1671
                      config->readNumEntry("HTTPProxyPort",proxyPort));
 
1672
 
 
1673
    current_server = config->readEntry("CurrentServer",DEFAULT_CDDB_SERVER);
 
1674
    //Let's check if it is in old format and if so, convert it to new one:
 
1675
    if(CDDB::normalize_server_list_entry(current_server))
 
1676
    {
 
1677
        kdDebug() << "Default freedb server entry converted to new format and saved.\n" << endl;
 
1678
        config->writeEntry("CurrentServer",current_server);
 
1679
        config->sync();
 
1680
    }
 
1681
    submitaddress = config->readEntry("CDDBSubmitAddress","freedb-submit@freedb.org");
 
1682
    cddbserverlist = config->readListEntry("SeverList", ',');
 
1683
    int num = cddbserverlist.count();
 
1684
    if (num == 0)
 
1685
        cddbserverlist.append(DEFAULT_CDDB_SERVER);
 
1686
    else
 
1687
    {
 
1688
        //Let's check if it is in old format and if so, convert it to new one:
 
1689
        bool needtosave=false;
 
1690
        QStringList nlist;
 
1691
 
 
1692
        for ( QStringList::Iterator it = cddbserverlist.begin();
 
1693
              it != cddbserverlist.end();
 
1694
              ++it )
 
1695
        {
 
1696
            needtosave|=CDDB::normalize_server_list_entry(*it);
 
1697
            nlist.append(*it);
 
1698
        }
 
1699
        if(needtosave)
 
1700
        {
 
1701
            // I have to recreate list because of sytange behaviour of sync()
 
1702
            // function in configuration - it does not notice if QStringList
 
1703
            // String contents is changed.
 
1704
            cddbserverlist=nlist;
 
1705
            kdDebug() << "freedb server list converted to new format and saved.\n" << endl;
 
1706
            config->writeEntry("SeverList",cddbserverlist,',',true);
 
1707
            config->sync();
 
1708
        }
 
1709
    }
 
1710
    cddbsubmitlist = config->readListEntry("SubmitList", ',');
 
1711
    num = cddbsubmitlist.count();
 
1712
    if(!num){
 
1713
        cddbsubmitlist.append(DEFAULT_SUBMIT_EMAIL);
 
1714
        cddbsubmitlist.append(DEFAULT_TEST_EMAIL);
 
1715
    }
 
1716
}
 
1717
 
 
1718
/**
 
1719
 * Write KSCD's Configuration into the kderc file.
 
1720
 *
 
1721
 */
 
1722
void
 
1723
KSCD::writeSettings()
 
1724
{
 
1725
    config = kapp->config();
 
1726
 
 
1727
    config->setGroup("GENERAL");
 
1728
    config->writeEntry("ToolTips", tooltips);
 
1729
    config->writeEntry("RandomPlay", randomplay);
 
1730
    config->writeEntry("USEKFM", use_kfm);
 
1731
    config->writeEntry("DOCKING", docking);
 
1732
    config->writeEntry("AUTOPLAY", autoplay);
 
1733
    config->writeEntry("STOPEXIT", stopexit);
 
1734
    config->writeEntry("EJECTONFINISH", ejectonfinish);
 
1735
    config->writeEntry("RANDOMONCE", randomonce);
 
1736
    config->writeEntry("CDDevice", QFile::decodeName(cd_device));
 
1737
    config->writeEntry("CustomBrowserCmd",browsercmd);
 
1738
    config->writeEntry("Volume", volume);
 
1739
    config->writeEntry("BackColor",background_color);
 
1740
    config->writeEntry("LEDColor",led_color);
 
1741
    config->writeEntry("Looping", looping);
 
1742
 
 
1743
    config->setGroup("SMTP");
 
1744
    config->writeEntry("enabled", smtpConfigData.enabled);
 
1745
    config->writeEntry("mailProfile", smtpConfigData.mailProfile);
 
1746
 
 
1747
    config->setGroup("CDDB");
 
1748
    config->writeEntry("CDDBRemoteEnabled",cddb_remote_enabled);
 
1749
    config->writeEntry("CDDBTimeout",cddb.getTimeout());
 
1750
    config->writeEntry("CDDBLocalAutoSaveEnabled",cddb_auto_enabled);
 
1751
 
 
1752
    config->writeEntry("LocalBaseDir",cddbbasedir);
 
1753
    config->writeEntry("SeverList",cddbserverlist);
 
1754
    config->writeEntry("SubmitList", cddbsubmitlist);
 
1755
    config->writeEntry("CDDBSubmitAddress",submitaddress);
 
1756
    config->writeEntry("CurrentServer",current_server);
 
1757
    config->writeEntry("CDDBHTTPProxyEnabled",cddb.useHTTPProxy());
 
1758
    config->writeEntry("HTTPProxyHost",cddb.getHTTPProxyHost());
 
1759
    config->writeEntry("HTTPProxyPort",(int)cddb.getHTTPProxyPort());
 
1760
 
 
1761
    config->setGroup("MAGIC");
 
1762
    config->writeEntry("magicwidth",magic_width);
 
1763
    config->writeEntry("magicheight",magic_height);
 
1764
    config->writeEntry("magicbrightness",magic_brightness);
 
1765
    config->writeEntry("magicPointsAreDiamonds",magic_pointsAreDiamonds);
 
1766
 
 
1767
    config->sync();
 
1768
} // writeSettings()
 
1769
 
 
1770
void
 
1771
KSCD::CDDialogSelected()
 
1772
{
 
1773
    kdDebug() << "CDDialogSelected" << endl;
 
1774
    if(cddialog)
 
1775
        return;
 
1776
 
 
1777
        kdDebug() << "dialog was empty" << endl;
 
1778
 
 
1779
    cddialog = new CDDialog();
 
1780
 
 
1781
    cddialog->setData(cd,tracktitlelist,extlist,discidlist,xmcd_data,category,
 
1782
                      revision,playlist,pathlist,cddbbasedir,submitaddress, &smtpConfigData);
 
1783
 
 
1784
    connect(cddialog,SIGNAL(cddb_query_signal(bool)),this,SLOT(get_cddb_info(bool)));
 
1785
    connect(cddialog,SIGNAL(dialog_done()),this,SLOT(CDDialogDone()));
 
1786
    connect(cddialog,SIGNAL(play_signal(int)),this,SLOT(trackSelected(int)));
 
1787
 
 
1788
    cddialog->show();
 
1789
}
 
1790
 
 
1791
void
 
1792
KSCD::CDDialogDone()
 
1793
{
 
1794
        kdDebug() << "cddialog -> done" << endl;
 
1795
    delete cddialog;
 
1796
    cddialog = 0L;
 
1797
}
 
1798
 
 
1799
 
 
1800
void
 
1801
KSCD::getCDDBservers()
 
1802
{
 
1803
    led_on();
 
1804
 
 
1805
    // Get current server and proxy settings from CDDB setup dialog befoe proceed
 
1806
    bool    cddb_proxy_enabled;
 
1807
    QString cddb_proxy_host;
 
1808
    unsigned short int cddb_proxy_port;
 
1809
    unsigned short int cddb_timeout;
 
1810
 
 
1811
    setup->getData(cddbserverlist,
 
1812
                   cddbsubmitlist,
 
1813
                   cddbbasedir,
 
1814
                   submitaddress,
 
1815
                   current_server,
 
1816
                   cddb_auto_enabled,
 
1817
                   cddb_remote_enabled,
 
1818
                   cddb_timeout,
 
1819
                   cddb_proxy_enabled,
 
1820
                   cddb_proxy_host,
 
1821
                   cddb_proxy_port
 
1822
        );
 
1823
    cddb.setTimeout(cddb_timeout);
 
1824
    cddb.setHTTPProxy(cddb_proxy_host,cddb_proxy_port);
 
1825
    cddb.useHTTPProxy(cddb_proxy_enabled);
 
1826
 
 
1827
    connect(&cddb,SIGNAL(get_server_list_done()),this,SLOT(getCDDBserversDone()));
 
1828
    connect(&cddb,SIGNAL(get_server_list_failed()),this,SLOT(getCDDBserversFailed()));
 
1829
 
 
1830
    // For now, just don't update if there's no current server.
 
1831
    if(!current_server.isEmpty())
 
1832
        cddb.cddbgetServerList(current_server);
 
1833
} // getCDDBservers()
 
1834
 
 
1835
void
 
1836
KSCD::getCDDBserversFailed()
 
1837
{
 
1838
 
 
1839
    led_off();
 
1840
    disconnect(&cddb,SIGNAL(get_server_list_done()),this,SLOT(getCDDBserversDone()));
 
1841
    disconnect(&cddb,SIGNAL(get_server_list_failed()),this,SLOT(getCDDBserversFailed()));
 
1842
    setArtistAndTitle(i18n("Unable to get freedb server list."), "");
 
1843
    titlelabeltimer->start(10000,TRUE); // 10 secs
 
1844
}
 
1845
 
 
1846
void
 
1847
KSCD::getCDDBserversDone()
 
1848
{
 
1849
 
 
1850
    led_off();
 
1851
    disconnect(&cddb,SIGNAL(get_server_list_done()),this,SLOT(getCDDBserversDone()));
 
1852
    disconnect(&cddb,SIGNAL(get_server_list_failed()),this,SLOT(getCDDBserversFailed()));
 
1853
    cddb.serverList(cddbserverlist);
 
1854
    if(setup)
 
1855
        setup->insertServerList(cddbserverlist);
 
1856
}
 
1857
 
 
1858
#ifdef NEEDOWNCDDBDISCID
 
1859
int
 
1860
cddb_sum(int n)
 
1861
{
 
1862
    char    buf[12];
 
1863
    char    *p;
 
1864
    int     ret = 0;
 
1865
    long unsigned int ntemp = 0;
 
1866
    ntemp = (long unsigned int) n;
 
1867
 
 
1868
    /* For backward compatibility this algorithm must not change */
 
1869
    sprintf(buf, "%lu", ntemp);
 
1870
    for (p = buf; *p != '\0'; p++)
 
1871
        ret += (*p - '0');
 
1872
 
 
1873
    return (ret);
 
1874
}
 
1875
 
 
1876
unsigned long
 
1877
cddb_discid()
 
1878
{
 
1879
    int     i;
 
1880
    int     t = 0;
 
1881
    int     n = 0;
 
1882
    int     min, sec;
 
1883
 
 
1884
 
 
1885
    /* For backward compatibility this algorithm must not change */
 
1886
    for (i = 0; i < thicd.ntracks; i++)
 
1887
    {
 
1888
        /*
 
1889
        min = thiscd.trk[i].start / (4500); // 60 * 75
 
1890
            sec = (thiscd.trk[i].start % (4500)) / 75;
 
1891
            n += cddb_sum((min * 60) + sec);
 
1892
*/
 
1893
        n += cddb_sum(thiscd.trk[i].start / 75);
 
1894
    }
 
1895
 
 
1896
    /*
 
1897
    t = ((thiscd.cddbtoc[thiscd.ntracks].min * 60)
 
1898
             + thiscd.cddbtoc[thiscd.ntracks].sec) -
 
1899
             ((thiscd.cddbtoc[0].min * 60) + thiscd.cddbtoc[0].sec);
 
1900
*/
 
1901
    t = ((thiscd.trk[thiscd.ntracks].start / 75) -
 
1902
         (thiscd.trk[0].start / 75));
 
1903
 
 
1904
    return ((n % 0xff) << 24 | t << 8 | thiscd.ntracks);
 
1905
}
 
1906
 
 
1907
#endif
 
1908
 
 
1909
void
 
1910
KSCD::get_cddb_info(bool _updateDialog)
 
1911
{
 
1912
    static int connected = 0;
 
1913
 
 
1914
    updateDialog = _updateDialog;
 
1915
 
 
1916
    QTime dml;
 
1917
    dml = dml.addSecs(cd->length);
 
1918
 
 
1919
    QString fmt;
 
1920
    if(dml.hour() > 0)
 
1921
        fmt.sprintf("%02d:%02d:%02d",dml.hour(),dml.minute(),dml.second());
 
1922
    else
 
1923
        fmt.sprintf("%02d:%02d",dml.minute(),dml.second());
 
1924
 
 
1925
    totaltimelabel->setText(fmt);
 
1926
 
 
1927
    get_pathlist(pathlist);
 
1928
    cddb.setPathList(pathlist);
 
1929
 
 
1930
    if(!connected){
 
1931
        connect(&cddb,SIGNAL(cddb_ready()),this,SLOT(cddb_ready()));
 
1932
        connect(&cddb,SIGNAL(cddb_failed()),this,SLOT(cddb_failed()));
 
1933
        connect(&cddb,SIGNAL(cddb_done()),this,SLOT(cddb_done()));
 
1934
        connect(&cddb,SIGNAL(cddb_timed_out()),this,SLOT(cddb_timed_out()));
 
1935
        connect(&cddb,SIGNAL(cddb_inexact_read()),this,SLOT(mycddb_inexact_read()));
 
1936
        connect(&cddb,SIGNAL(cddb_no_info()),this,SLOT(cddb_no_info()));
 
1937
        connected = 1;
 
1938
    }
 
1939
    led_on();
 
1940
 
 
1941
    bool res = cddb.local_query(
 
1942
        cddb_discid(),
 
1943
        xmcd_data,
 
1944
        tracktitlelist,
 
1945
        extlist,
 
1946
        category,
 
1947
        discidlist,
 
1948
        revision,
 
1949
        playlist
 
1950
        );
 
1951
    Fetch_remote_cddb = false;
 
1952
    if(!res && !cddb_remote_enabled){
 
1953
        //    have_new_cd = false;
 
1954
        cddb_no_info();
 
1955
        return;
 
1956
    }
 
1957
 
 
1958
    if(!res){
 
1959
 
 
1960
        kdDebug() << "STARTING REMOTE QUERY\n" << endl;
 
1961
        cddb.cddb_connect(current_server);
 
1962
        Fetch_remote_cddb = true;
 
1963
 
 
1964
    }
 
1965
    else{
 
1966
        kdDebug() << "FOUND RECORD LOCALLY\n" << endl;
 
1967
        if((int)tracktitlelist.count() != (cd->ntracks + 1)){
 
1968
            kdDebug() << "WARNING LOCAL QUERY tracktitleslist.count = " << tracktitlelist.count() << " != cd->ntracks +1 = " << cd->ntracks + 1 << "\n" << endl;
 
1969
        }
 
1970
 
 
1971
        if((int)extlist.count() != (cd->ntracks + 1)){
 
1972
            kdDebug() << "WARNING LOCAL QUERYextlist.count = " << extlist.count() << " != cd->ntracks +1 = " << cd->ntracks + 1 << "\n" << endl;
 
1973
        }
 
1974
 
 
1975
        if(tracktitlelist.count() > 1){
 
1976
            setArtistAndTitle(tracktitlelist.first(),
 
1977
                              *tracktitlelist.at(1));
 
1978
        }
 
1979
 
 
1980
        int i = 0;
 
1981
        songListCB->clear();
 
1982
        QStringList::Iterator it = tracktitlelist.begin();
 
1983
        ++it;
 
1984
        for ( ; it != tracktitlelist.end(); ++it )
 
1985
        {
 
1986
            i++;
 
1987
            songListCB->insertItem( QString("").sprintf("%02d: %s", i, (*it).utf8().data()));
 
1988
        }
 
1989
        for(; i < cur_ntracks; i++){
 
1990
            songListCB->insertItem( QString::fromUtf8(QCString("").sprintf(i18n("%02d: <Unknown>").utf8(), i+1)) );
 
1991
        }
 
1992
 
 
1993
 
 
1994
        led_off();
 
1995
        timer->start(1000);
 
1996
 
 
1997
        if(cddialog && updateDialog)
 
1998
            cddialog->setData(cd,tracktitlelist,extlist,discidlist,xmcd_data,category,
 
1999
                              revision,playlist,pathlist,cddbbasedir,submitaddress, &smtpConfigData);
 
2000
        playlistpointer = 0;
 
2001
    }
 
2002
 
 
2003
    //  have_new_cd = false;
 
2004
 
 
2005
} // get_cddb_info
 
2006
 
 
2007
int cddb_ready_bug = 0;
 
2008
void
 
2009
KSCD::cddb_ready()
 
2010
{
 
2011
    kdDebug() << "cddb_ready() called\n" << endl;
 
2012
 
 
2013
    if(!cd)
 
2014
        return;
 
2015
/*    if(cddb_ready_bug)
 
2016
      return;
 
2017
    cddb_ready_bug = 1;
 
2018
*/
 
2019
    querylist.clear();
 
2020
    tracktitlelist.clear();
 
2021
        setArtistAndTitle("", "");
 
2022
        extlist.clear();
 
2023
    discidlist.clear();
 
2024
 
 
2025
    QCString num;
 
2026
 
 
2027
    for(int i = 0 ; i < cd->ntracks; i++)
 
2028
    {
 
2029
        querylist.append(num.setNum(cd->trk[i].start));
 
2030
    }
 
2031
 
 
2032
    querylist.append(num.setNum(cd->trk[cd->ntracks].start/75));
 
2033
    cddb_inexact_sentinel =false;
 
2034
    cddb.queryCD(cddb_discid(),querylist);
 
2035
} // cddb_ready
 
2036
 
 
2037
#define DEFINE_CDTEXT
 
2038
#define CDTEXT_MACRO \
 
2039
    if(wm_cdtext_info.valid){\
 
2040
        kdDebug() << "CDTEXT_MACRO called" << endl;\
 
2041
        int at;\
 
2042
    setArtistAndTitle("", ""); \
 
2043
    tracktitlelist.clear(); \
 
2044
    extlist.clear(); \
 
2045
        tracktitlelist.append(QString().sprintf("%s / %s", (const char*)(wm_cdtext_info.blocks[0]->name[0]),(const char*)(wm_cdtext_info.blocks[0]->performer[0])));\
 
2046
        titlelabel->setText(QString((const char*)(wm_cdtext_info.blocks[0]->name[1])));\
 
2047
        artistlabel->setText(tracktitlelist.first());\
 
2048
        songListCB->clear();\
 
2049
        for (at = 1 ; at < (wm_cdtext_info.count_of_entries); ++at ) {\
 
2050
            songListCB->insertItem( QString().sprintf("%02d: %s", at, wm_cdtext_info.blocks[0]->name[at]));\
 
2051
            tracktitlelist.append((const char*)(wm_cdtext_info.blocks[0]->name[at]));\
 
2052
        }\
 
2053
        for(; at < cur_ntracks; ++at){\
 
2054
            songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), at)));\
 
2055
        }\
 
2056
}
 
2057
 
 
2058
void
 
2059
KSCD::cddb_no_info()
 
2060
{
 
2061
 
 
2062
    //        cddb_ready_bug = 0;
 
2063
    kdDebug() << "cddb_no_info() called\n" << endl;
 
2064
 
 
2065
    setArtistAndTitle(i18n("No matching freedb entry found."), "");
 
2066
//    artistlabel->clear();
 
2067
//    titlelabeltimer->start(10000,TRUE); // 10 secs
 
2068
 
 
2069
 
 
2070
        setArtistAndTitle("", "");
 
2071
        tracktitlelist.clear();
 
2072
        extlist.clear();
 
2073
    tracktitlelist.append(i18n("No matching freedb entry found."));
 
2074
#ifdef DEFINE_CDTEXT
 
2075
    wm_cd_get_cdtext();
 
2076
    CDTEXT_MACRO
 
2077
    else
 
2078
#endif /* DEFINE_CDTEXT */
 
2079
    {
 
2080
       discidlist.clear();
 
2081
    }
 
2082
    timer->start(1000);
 
2083
    led_off();
 
2084
    cddb_inexact_sentinel =false;
 
2085
 
 
2086
    int i = 0;
 
2087
    songListCB->clear();
 
2088
    QStringList::Iterator it = tracktitlelist.begin();
 
2089
    ++it;
 
2090
    for ( ; it != tracktitlelist.end(); ++it )
 
2091
      {
 
2092
        i++;
 
2093
        songListCB->insertItem( QString("").sprintf("%02d: %s", i, (*it).utf8().data()));
 
2094
      }
 
2095
    for(; i < cur_ntracks; i++)
 
2096
      {
 
2097
        songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), i+1)) );
 
2098
      }
 
2099
    //    cddb_error = 1;
 
2100
} // cddb_no_info
 
2101
 
 
2102
void
 
2103
KSCD::cddb_failed()
 
2104
{
 
2105
    // TODO differentiate between those casees where the communcition really
 
2106
    // failed and those where we just couldn't find anything
 
2107
    //        cddb_ready_bug = 0;
 
2108
    kdDebug() << "cddb_failed() called\n" << endl;
 
2109
        setArtistAndTitle("", "");
 
2110
        tracktitlelist.clear();
 
2111
        extlist.clear();
 
2112
    tracktitlelist.append(i18n("Error getting freedb entry."));
 
2113
#ifdef DEFINE_CDTEXT
 
2114
    CDTEXT_MACRO
 
2115
    else
 
2116
#endif /* DEFINE_CDTEXT */
 
2117
    {
 
2118
      for(int i = 0 ; i < cd->ntracks; i++)
 
2119
        tracktitlelist.append("");
 
2120
 
 
2121
      extlist.clear();
 
2122
      for(int i = 0 ; i <= cd->ntracks; i++)
 
2123
        extlist.append("");
 
2124
 
 
2125
      discidlist.clear();
 
2126
 
 
2127
      setArtistAndTitle(i18n("Error getting freedb entry."), "");
 
2128
//    titlelabeltimer->start(10000,TRUE); // 10 secs
 
2129
    }
 
2130
    timer->start(1000);
 
2131
    led_off();
 
2132
    cddb_inexact_sentinel =false;
 
2133
//    cddb_error = 1;
 
2134
} // cddb_failed
 
2135
 
 
2136
void
 
2137
KSCD::cddb_timed_out()
 
2138
{
 
2139
//    cddb_ready_bug = 0;
 
2140
    kdDebug() << "cddb_timed_out() called\n" << endl;
 
2141
        tracktitlelist.clear();
 
2142
        setArtistAndTitle("", "");
 
2143
        extlist.clear();
 
2144
      tracktitlelist.append(i18n("freedb query timed out."));
 
2145
#ifdef DEFINE_CDTEXT
 
2146
    CDTEXT_MACRO
 
2147
    else
 
2148
#endif /* DEFINE_CDTEXT */
 
2149
    {
 
2150
      for(int i = 0 ; i <= cd->ntracks; i++)
 
2151
        tracktitlelist.append("");
 
2152
 
 
2153
      extlist.clear();
 
2154
      for(int i = 0 ; i <= cd->ntracks; i++)
 
2155
        extlist.append("");
 
2156
 
 
2157
      discidlist.clear();
 
2158
 
 
2159
      setArtistAndTitle(i18n("freedb query timed out."),"");
 
2160
//    titlelabeltimer->start(10000,TRUE); // 10 secs
 
2161
    }
 
2162
    timer->start(1000);
 
2163
    led_off();
 
2164
    cddb_inexact_sentinel =false;
 
2165
//    cddb_error = 1;
 
2166
} // cddb_timed_out()
 
2167
 
 
2168
void
 
2169
KSCD::mycddb_inexact_read()
 
2170
{
 
2171
    if(cddb_inexact_sentinel == true)
 
2172
        return;
 
2173
 
 
2174
    QString pick;
 
2175
 
 
2176
    cddb_inexact_sentinel = true;
 
2177
    QStringList inexact_list;
 
2178
        cddb.get_inexact_list(inexact_list);
 
2179
 
 
2180
    // Whatever happens, we better clear the list beforehand
 
2181
        setArtistAndTitle("", "");
 
2182
        tracktitlelist.clear();
 
2183
        extlist.clear();
 
2184
 
 
2185
    if( inexact_list.count() == 1)
 
2186
    {
 
2187
        pick = inexact_list.first();
 
2188
        cddb.query_exact("200 " + pick);
 
2189
        return;
 
2190
    }
 
2191
 
 
2192
    InexactDialog *dialog;
 
2193
    dialog = new InexactDialog(0,"inexactDialog",true);
 
2194
    dialog->insertList(inexact_list);
 
2195
 
 
2196
    if(dialog->exec() != QDialog::Accepted)
 
2197
    {
 
2198
        cddb.close_connection();
 
2199
        timer->start(1000);
 
2200
        led_off();
 
2201
        return;
 
2202
    }
 
2203
 
 
2204
    dialog->getSelection(pick);
 
2205
    delete dialog;
 
2206
 
 
2207
 
 
2208
    if(pick.isEmpty())
 
2209
    {
 
2210
        timer->start(1000);
 
2211
        led_off();
 
2212
        return;
 
2213
    }
 
2214
 
 
2215
    pick = "200 " + pick;
 
2216
    cddb.query_exact(pick);
 
2217
} // mycddb_inexact_read
 
2218
 
 
2219
void
 
2220
KSCD::cddb_done()
 
2221
{
 
2222
    cddb_inexact_sentinel =false;
 
2223
 
 
2224
    kdDebug() << "cddb_done() called\n" << endl;
 
2225
//    cddb_ready_bug = 0;
 
2226
    cddb.getData(xmcd_data,tracktitlelist,extlist,category,discidlist,revision,playlist);
 
2227
    playlistpointer = 0;
 
2228
 
 
2229
    if((int)tracktitlelist.count() != (cd->ntracks + 1)){
 
2230
        kdDebug() << "WARNING tracktitleslist.count = " << tracktitlelist.count() << " != cd->ntracks +1 = " << cd->ntracks + 1 << "\n" << endl;
 
2231
    }
 
2232
 
 
2233
    if((int)extlist.count() != (cd->ntracks + 1)){
 
2234
        kdDebug() << "WARNING extlist.count = " << extlist.count() << " != cd->ntracks +1 = " << cd->ntracks + 1 << "\n" << endl;
 
2235
    }
 
2236
 
 
2237
    if(tracktitlelist.count() > 1){
 
2238
        setArtistAndTitle(tracktitlelist.first(),
 
2239
                          *tracktitlelist.at(1));
 
2240
    }
 
2241
 
 
2242
    if(cddialog && updateDialog)
 
2243
        cddialog->setData(cd,tracktitlelist,extlist,discidlist,xmcd_data,category,
 
2244
                          revision,playlist,pathlist,cddbbasedir,submitaddress, &smtpConfigData);
 
2245
 
 
2246
    int i = 0;
 
2247
    songListCB->clear();
 
2248
    QStringList::Iterator it = tracktitlelist.begin();
 
2249
    ++it;
 
2250
    for ( ; it != tracktitlelist.end(); ++it )
 
2251
    {
 
2252
        i++;
 
2253
        songListCB->insertItem( QString("").sprintf("%02d: %s", i, (*it).utf8().data()));
 
2254
    }
 
2255
    for(; i < cur_ntracks; i++){
 
2256
        songListCB->insertItem( QString::fromUtf8( QCString().sprintf(i18n("%02d: <Unknown>").utf8(), i+1)) );
 
2257
    }
 
2258
 
 
2259
//    for (int i = 0; i < cur_ntracks; i++){
 
2260
//        songListCB->insertItem( QString( 0 ).sprintf( i18n("Track %02d"), i + 1 ) );
 
2261
    //    }
 
2262
 
 
2263
    led_off();
 
2264
    if(Fetch_remote_cddb)
 
2265
    {
 
2266
        if(cddb_auto_enabled)
 
2267
        {
 
2268
            QString path,tmp;
 
2269
            tmp.sprintf("/%08lx",cddb_discid());
 
2270
            path = cddbbasedir;
 
2271
            path += "/";
 
2272
            path += category;
 
2273
            path += tmp;
 
2274
            //      kdDebug() << path << endl << cddbbasedir << category << cddb_discid() << endl;
 
2275
            path.replace(QRegExp("//"),"/");
 
2276
            edm_save_cddb_entry(path);
 
2277
        }
 
2278
    }
 
2279
    timer->start(1000);
 
2280
} // cddb_done
 
2281
 
 
2282
void
 
2283
KSCD::led_off()
 
2284
{
 
2285
    queryledtimer->stop();
 
2286
    queryled->off();
 
2287
    queryled->hide();
 
2288
    totaltimelabel->raise();
 
2289
    totaltimelabel->show();
 
2290
 
 
2291
} // led_off
 
2292
 
 
2293
void
 
2294
KSCD::led_on()
 
2295
{
 
2296
    totaltimelabel->hide();
 
2297
    totaltimelabel->lower();
 
2298
    queryledtimer->start(800);
 
2299
    queryled->off();
 
2300
    queryled->show();
 
2301
    kapp->processEvents();
 
2302
    kapp->flushX();
 
2303
} // led_on
 
2304
 
 
2305
void
 
2306
KSCD::togglequeryled()
 
2307
{
 
2308
    queryled->show();
 
2309
    queryled->toggle();
 
2310
 
 
2311
} // togglequeryled
 
2312
 
 
2313
void
 
2314
KSCD::titlelabeltimeout()
 
2315
{
 
2316
    // clear the cddb error message on the title label.
 
2317
    titlelabeltimer->stop();
 
2318
    titlelabel->clear();
 
2319
 
 
2320
} // titlelabeltimeout
 
2321
 
 
2322
void
 
2323
KSCD::setArtistAndTitle(const QString& artist, const QString& title)
 
2324
{
 
2325
    QString tooltip = "";
 
2326
    if (!artist.isEmpty()) {
 
2327
        artistlabel->setText(artist);
 
2328
        tooltip = KStringHandler::rsqueeze(artist, 30) + "\n";
 
2329
    }
 
2330
    else {
 
2331
        artistlabel->clear();
 
2332
    }
 
2333
 
 
2334
    if (!title.isEmpty()) {
 
2335
        titlelabel->setText(title);
 
2336
        tooltip += KStringHandler::rsqueeze(title,30);
 
2337
    }
 
2338
    else {
 
2339
        titlelabel->clear();
 
2340
    }
 
2341
 
 
2342
    emit trackChanged(tooltip);
 
2343
}
 
2344
void
 
2345
KSCD::playtime()
 
2346
{
 
2347
    static int mymin;
 
2348
    static int mysec;
 
2349
    int tmp = 0;
 
2350
 
 
2351
    switch(time_display_mode){
 
2352
 
 
2353
        case TRACK_REM:
 
2354
 
 
2355
            tmp = cur_tracklen - cur_pos_rel;
 
2356
            mysec = tmp % 60;
 
2357
            mymin = tmp / 60;
 
2358
            break;
 
2359
 
 
2360
        case TOTAL_SEC:
 
2361
 
 
2362
            mysec = cur_pos_abs % 60;
 
2363
            mymin = cur_pos_abs / 60;
 
2364
            break;
 
2365
 
 
2366
        case TOTAL_REM:
 
2367
 
 
2368
            tmp = cur_cdlen - cur_pos_abs;
 
2369
            mysec = tmp % 60;
 
2370
            mymin = tmp / 60;
 
2371
 
 
2372
            break;
 
2373
 
 
2374
        case TRACK_SEC:
 
2375
        default:
 
2376
 
 
2377
            if (cur_pos_rel > 0 && (tmp = cur_pos_rel % 60) == mysec)
 
2378
                return;
 
2379
            mysec = tmp;
 
2380
            mymin = cur_pos_rel / 60;
 
2381
 
 
2382
            break;
 
2383
    }
 
2384
 
 
2385
 
 
2386
    sprintf( tmptime, "%02d:%02d", mymin, mysec );
 
2387
    return;
 
2388
 
 
2389
} // playtime
 
2390
 
 
2391
void
 
2392
KSCD::cycleplaytimemode()
 
2393
{
 
2394
    cycletimer->stop();
 
2395
 
 
2396
    if (++time_display_mode > 3)
 
2397
        time_display_mode = 0;
 
2398
    playtime();
 
2399
    setLEDs( tmptime );
 
2400
 
 
2401
 
 
2402
    switch(time_display_mode){
 
2403
 
 
2404
        case TRACK_REM:
 
2405
            volumelabel->setText(i18n("Tra Rem"));
 
2406
            break;
 
2407
 
 
2408
        case TOTAL_SEC:
 
2409
            volumelabel->setText(i18n("Tot Sec"));
 
2410
            break;
 
2411
 
 
2412
        case TOTAL_REM:
 
2413
            volumelabel->setText(i18n("Tot Rem"));
 
2414
            break;
 
2415
 
 
2416
        case TRACK_SEC:
 
2417
        default:
 
2418
            volumelabel->setText(i18n("Tra Sec"));
 
2419
            break;
 
2420
    }
 
2421
 
 
2422
    cycletimer->start(3000,TRUE);
 
2423
} // cycleplaymode
 
2424
 
 
2425
void
 
2426
KSCD::cycletimeout()
 
2427
{
 
2428
    cycletimer->stop();
 
2429
    QString str;
 
2430
    str = QString::fromUtf8( QCString().sprintf(i18n("Vol: %02d%%").utf8(),volume) );
 
2431
    volumelabel->setText(str);
 
2432
 
 
2433
} // cycletimeout
 
2434
 
 
2435
 
 
2436
bool
 
2437
KSCD::getArtist(QString& artist)
 
2438
{
 
2439
    if((int)tracktitlelist.isEmpty()){
 
2440
        return false;
 
2441
    }
 
2442
 
 
2443
    artist = tracktitlelist.first();
 
2444
 
 
2445
    int pos;
 
2446
    pos = artist.find('/', 0, true);
 
2447
    if(pos != -1)
 
2448
        artist.truncate(pos);
 
2449
 
 
2450
    artist = artist.stripWhiteSpace();
 
2451
    return true;
 
2452
 
 
2453
} // getArtist
 
2454
 
 
2455
void
 
2456
KSCD::performances(int i)
 
2457
{
 
2458
    kdDebug() << "preformances " << i << "\n" << endl;
 
2459
 
 
2460
    QString artist;
 
2461
    QString str;
 
2462
 
 
2463
    if(!getArtist(artist))
 
2464
        return;
 
2465
 
 
2466
    // primitive incomplete http encoding TODO fix!
 
2467
    artist = artist.replace( QRegExp(" "), "+" );
 
2468
 
 
2469
    switch(i){
 
2470
        case 0:
 
2471
            str =
 
2472
                QString("http://www.tourdates.com/cgi-bin/search.cgi?type=Artist&search=%1")
 
2473
                .arg(artist);
 
2474
            startBrowser(str);
 
2475
 
 
2476
            break;
 
2477
 
 
2478
        default:
 
2479
            break;
 
2480
    }
 
2481
 
 
2482
} // performances
 
2483
 
 
2484
void
 
2485
KSCD::purchases(int i)
 
2486
{
 
2487
    kdDebug() << "purchases " << i << "\n" << endl;
 
2488
 
 
2489
    QString artist;
 
2490
    QString str;
 
2491
 
 
2492
    if(!getArtist(artist))
 
2493
        return;
 
2494
 
 
2495
    // primitive incomplete http encoding TODO fix!
 
2496
    artist = artist.replace( QRegExp(" "), "+" );
 
2497
 
 
2498
    switch(i){
 
2499
        case 0:
 
2500
            str =
 
2501
                QString("http://cdnow.com/switch/from=sr-288025/target=buyweb_products/artfs=%1")
 
2502
                .arg(artist);
 
2503
            startBrowser(str);
 
2504
 
 
2505
            break;
 
2506
        case 1:
 
2507
            str =
 
2508
                QString("http://www.cduniverse.com/cgi-bin/cdubin.exe/rlinka/ean=%1")
 
2509
                .arg(artist);
 
2510
            startBrowser(str);
 
2511
 
 
2512
            break;
 
2513
 
 
2514
        default:
 
2515
            break;
 
2516
    }
 
2517
 
 
2518
} // purchases
 
2519
 
 
2520
void
 
2521
KSCD::magicslot()
 
2522
{
 
2523
    magicslot(0);
 
2524
}
 
2525
 
 
2526
void
 
2527
KSCD::magicslot( int )
 
2528
{
 
2529
    if(magicproc && magicproc->isRunning())
 
2530
    {
 
2531
        return;
 
2532
    }
 
2533
 
 
2534
    magicproc = 0L;
 
2535
    magicproc = new KProcess;
 
2536
 
 
2537
    QString b;
 
2538
    b.setNum(magic_brightness);
 
2539
    QString w;
 
2540
    w.setNum(magic_width);
 
2541
    QString h;
 
2542
    h.setNum(magic_height);
 
2543
 
 
2544
    *magicproc << "kscdmagic" << " -b" << b << " -w"<< w << " -h" << h;
 
2545
 
 
2546
    connect(magicproc,
 
2547
            SIGNAL(processExited(KProcess *)),this, SLOT(magicdone(KProcess*)));
 
2548
 
 
2549
 
 
2550
    bool result = magicproc->start(KProcess::NotifyOnExit , KProcess::Stdin);
 
2551
 
 
2552
    if(!result)
 
2553
        KMessageBox::error(this, i18n("Cannot start kscdmagic."));
 
2554
    return;
 
2555
} // magicslot
 
2556
 
 
2557
void
 
2558
KSCD::magicdone(KProcess* proc)
 
2559
{
 
2560
    if(proc->normalExit())
 
2561
    {
 
2562
        //    fprintf(stderr,"kscdmagic exit status %d\n",proc->exitStatus());
 
2563
        if(proc->exitStatus()!=0)
 
2564
            KMessageBox::error(this, i18n("KSCD Magic exited abnormally.\n"
 
2565
                                          "Are you sure kscdmagic is installed?"));
 
2566
    }
 
2567
    //  printf("KSCD Magic Process Exited\n");
 
2568
 
 
2569
    if(proc)
 
2570
        delete proc;
 
2571
    magicproc = 0L;
 
2572
} // magicdone
 
2573
 
 
2574
void
 
2575
KSCD::information(int i)
 
2576
{
 
2577
    kdDebug() << "Information " << i << "\n" << endl;
 
2578
 
 
2579
    QString artist;
 
2580
    QString str;
 
2581
 
 
2582
    if(!getArtist(artist))
 
2583
        return;
 
2584
 
 
2585
    // primitive incomplete http encoding TODO fix!
 
2586
    artist = artist.replace( QRegExp(" "), "+" );
 
2587
 
 
2588
    switch(i)
 
2589
    {
 
2590
        case 0:
 
2591
            str =
 
2592
                QString("http://www.ubl.com/find/form?SEARCH=%1")
 
2593
                .arg(artist);
 
2594
            startBrowser(str);
 
2595
            break;
 
2596
 
 
2597
        case 2:
 
2598
            str =
 
2599
                QString("http://x8.dejanews.com/dnquery.xp?QRY=%1&defaultOp=AND&svcclass=dncurrent&maxhits=20&ST=QS&format=terse&DBS=2")
 
2600
                .arg(artist);
 
2601
            startBrowser(str);
 
2602
            break;
 
2603
 
 
2604
        case 3:
 
2605
            str =
 
2606
                QString("http://www.excite.com/search.gw?c=web&search=%1&trace=a")
 
2607
                .arg(artist);
 
2608
            startBrowser(str);
 
2609
            break;
 
2610
 
 
2611
        case 4:
 
2612
            str =
 
2613
                QString("http://www.search.hotbot.com/hResult.html?SW=web&SM=MC&MT=%1&DC=10&DE=2&RG=NA&_v=2")
 
2614
                .arg(artist);
 
2615
            startBrowser(str);
 
2616
            break;
 
2617
 
 
2618
        case 5:
 
2619
            str =
 
2620
                QString("http://www.infoseek.com/Titles?qt=%1&col=WW&sv=IS&lk=ip-noframes&nh=10")
 
2621
                .arg(artist);
 
2622
            startBrowser(str);
 
2623
            break;
 
2624
 
 
2625
        case 6:
 
2626
            str =
 
2627
                QString("http://www.lycos.com/cgi-bin/pursuit?cat=lycos&query=%1")
 
2628
                .arg(artist);
 
2629
            startBrowser(str);
 
2630
            break;
 
2631
 
 
2632
        case 7:
 
2633
            str =
 
2634
                QString("http://www.mckinley.com/search.gw?search=%1&c=web&look=magellan")
 
2635
                .arg(artist);
 
2636
            startBrowser(str);
 
2637
            break;
 
2638
 
 
2639
        case 8:
 
2640
            str =
 
2641
                QString("http://search.yahoo.com/bin/search?p=%1")
 
2642
                .arg(artist);
 
2643
            startBrowser(str);
 
2644
            break;
 
2645
 
 
2646
        default:
 
2647
            break;
 
2648
    } // switch()
 
2649
} // information
 
2650
 
 
2651
/**
 
2652
 * Open an URL with the user's favourite browser.
 
2653
 *
 
2654
 */
 
2655
void
 
2656
KSCD::startBrowser(const QString &querystring)
 
2657
{
 
2658
    if(use_kfm || browsercmd.isEmpty()) // default browser is KDE browser, no?
 
2659
    {
 
2660
        (void) new KRun ( querystring ); // replacement for KFM::openURL (David)
 
2661
    } else {
 
2662
        KProcess proc;
 
2663
        proc << browsercmd << querystring;
 
2664
        proc.start(KProcess::DontCare);
 
2665
    }
 
2666
} //startBrowser
 
2667
 
 
2668
 
 
2669
void
 
2670
KSCD::get_pathlist(QStringList& _pathlist)
 
2671
{
 
2672
    QDir d;
 
2673
    QStringList list;
 
2674
    InexactDialog *dialog;
 
2675
 
 
2676
    d.setFilter( QDir::Dirs);
 
2677
    d.setSorting( QDir::Size);
 
2678
    d.setPath(cddbbasedir);
 
2679
    if(!d.exists())
 
2680
    {
 
2681
        dialog = new InexactDialog(0, "dialog", false);
 
2682
        dialog->insertText(cddbbasedir);
 
2683
        dialog->setTitle(i18n("Enter the local freedb base Directory"));
 
2684
 
 
2685
        if(dialog->exec() != QDialog::Accepted)
 
2686
        {
 
2687
            delete dialog;
 
2688
            return;
 
2689
        }
 
2690
 
 
2691
        dialog->getSelection(cddbbasedir);
 
2692
        d.setPath(cddbbasedir);
 
2693
        delete dialog;
 
2694
    }
 
2695
 
 
2696
    if(!d.exists()) // Bogus directory, don't try to read it
 
2697
        return;
 
2698
 
 
2699
    _pathlist.clear();
 
2700
    list = d.entryList();
 
2701
 
 
2702
    for ( QStringList::ConstIterator it = list.begin();
 
2703
          it != list.end();
 
2704
          ++it )
 
2705
    {
 
2706
        if( *it != QString::fromLatin1(".") &&
 
2707
            *it != QString::fromLatin1("..") )
 
2708
        {
 
2709
            _pathlist.append( cddbbasedir + '/' +  *it);
 
2710
        }
 
2711
    }
 
2712
} // get_pathlist
 
2713
 
 
2714
 
 
2715
/*
 
2716
void KSCD::doSM()
 
2717
{
 
2718
  //WABA: Session management has changed
 
2719
 #if 1
 
2720
 #warning Session management is broken
 
2721
 #else
 
2722
    if (isVisible())
 
2723
          kapp->setWmCommand(QString(kapp->argv()[0])+" -caption \""+kapp->caption()+"\"");
 
2724
    else
 
2725
          kapp->setWmCommand(QString(kapp->argv()[0])+" -caption \""+kapp->caption()+"\" -hide ");
 
2726
 #endif
 
2727
} // doSM
 
2728
*/
 
2729
 
 
2730
void
 
2731
kcderror(const QString& title, const QString& message)
 
2732
{
 
2733
 KMessageBox::information(0L, message, title);
 
2734
}
 
2735
 
 
2736
/* I am dropping this code for now. People seem to be having nothing
 
2737
   but trouble with this code and it was of dubious value anyways....
 
2738
 
 
2739
   dfoerste: NOTES
 
2740
 
 
2741
1) Mark Buckaway checked only if there was an iso9660 filesystem mounted,
 
2742
   not if our device is mounted.
 
2743
2) Mount check only needs to be done before ejecting the disc.
 
2744
 
 
2745
#ifdef __linux__
 
2746
 
 
2747
// check if drive is mounted (from Mark Buckaway's cdplayer code)
 
2748
 
 
2749
 
 
2750
void
 
2751
KSCD::checkMount()
 
2752
{
 
2753
  if ((fp = setmntent (MOUNTED, "r")) == NULL)
 
2754
    {
 
2755
    fprintf (stderr, i18n("Couldn't open %s: %s\n"),
 
2756
               MOUNTED, strerror (errno));
 
2757
      exit (1);
 
2758
    }
 
2759
 
 
2760
    while ((mnt = getmntent (fp)) != NULL)
 
2761
    {
 
2762
    if (strcmp (mnt->mnt_type, "iso9660") == 0)
 
2763
        {
 
2764
        fputs (i18n("CDROM already mounted. Operation aborted.\n"),
 
2765
                 stderr);
 
2766
          endmntent (fp);
 
2767
          exit (1);
 
2768
        }
 
2769
        }
 
2770
        endmntent (fp);
 
2771
} // checkMount()
 
2772
 
 
2773
#elif defined (__FreeBSD__)
 
2774
void
 
2775
KSCD::checkMount()
 
2776
{
 
2777
  struct statfs *mnt;
 
2778
  int i, n;
 
2779
 
 
2780
  n = getmntinfo(&mnt, MNT_WAIT);
 
2781
  for (i=0; i<n; i++)
 
2782
    {
 
2783
    if (mnt[i].f_type == MOUNT_CD9660)
 
2784
        {
 
2785
        fputs(i18n("CDROM already mounted. Operation aborted.\n"),
 
2786
                stderr);
 
2787
          exit(1);
 
2788
        }
 
2789
        }
 
2790
        }
 
2791
 
 
2792
        #else
 
2793
 
 
2794
// TODO Can I do this for other platforms?
 
2795
   void
 
2796
   KSCD::checkMount()
 
2797
{
 
2798
}
 
2799
 
 
2800
#endif
 
2801
 */
 
2802
 
 
2803
void
 
2804
KSCD::make_random_list()
 
2805
{
 
2806
    /* koz: 15/01/00. I want a random list that does not repeat tracks. Ie, */
 
2807
    /* a list is created in which each track is listed only once. The tracks */
 
2808
    /* are picked off one by one until the end of the list */
 
2809
 
 
2810
    int selected,size,i,j;
 
2811
    bool rejected;
 
2812
 
 
2813
    if ( playlist.isEmpty() )
 
2814
        size = cur_ntracks;
 
2815
    else
 
2816
        size = playlist.count();
 
2817
 
 
2818
    kdDebug() << "Playlist has " << size << " entries\n" << endl;
 
2819
    random_list = (int *)malloc((size_t)size*sizeof(int));
 
2820
    for( i=0; i < size; i++ )
 
2821
    {
 
2822
        do {
 
2823
            rejected = false;
 
2824
            if( playlist.isEmpty() )
 
2825
                selected = 1 + (int) randSequence.getLong(size);
 
2826
            else
 
2827
                selected = (int) randSequence.getLong(size);
 
2828
 
 
2829
            for(j=0;j<i;j++)
 
2830
            {
 
2831
                if(random_list[j] == selected)
 
2832
                {
 
2833
                    rejected = true;
 
2834
                    break;
 
2835
                }
 
2836
            }
 
2837
        } while(rejected == true);
 
2838
        random_list[i] = selected;
 
2839
    }
 
2840
    random_current = 0; /* Index of array we are on */
 
2841
    return;
 
2842
} // make_random_list()
 
2843
 
 
2844
 
 
2845
void
 
2846
KSCD::edm_save_cddb_entry(QString& path)
 
2847
{
 
2848
 
 
2849
    kdDebug() << "::save_cddb_entry(): path: " << path << " edm" << "\n" << endl;
 
2850
 
 
2851
    QFile file(path); //open the file
 
2852
 
 
2853
 
 
2854
    if( !file.open( IO_WriteOnly  ))
 
2855
    {
 
2856
        QString str = i18n("Unable to write to file:\n%1\nPlease check "
 
2857
                           "your permissions and make your category directories exist.")
 
2858
                      .arg(path);
 
2859
 
 
2860
        KMessageBox::error(this, str);
 
2861
        return;
 
2862
    }
 
2863
 
 
2864
    QString tmp;
 
2865
    QTextStream t(&file);
 
2866
 
 
2867
    t << "# xmcd CD database file\n";
 
2868
 
 
2869
    QString datestr;
 
2870
    datestr = QDateTime::currentDateTime().toString();
 
2871
    tmp = QString("# Generated: %1 by KSCD\n").arg(datestr);
 
2872
    t << tmp;
 
2873
 
 
2874
    // Waste some disk space
 
2875
    t << "# Copyright (C) 1997-1999 Bernd Johannes Wuebben.\n";
 
2876
    t << "# Copyright (C) 1999-2001 Dirk Foersterling.\n";
 
2877
 
 
2878
 
 
2879
 
 
2880
    t << "# \n";
 
2881
    t << "# Track frame offsets:\n";
 
2882
 
 
2883
    for(int i = 0 ; i < cd->ntracks+1 ;i ++)
 
2884
    {
 
2885
        tmp = QString("#       %1\n").arg(cd->trk[i].start);
 
2886
        t << tmp;
 
2887
    }
 
2888
 
 
2889
    t << "#\n";
 
2890
    tmp = QString("# Disc length: %1 seconds\n").arg(cd->length);
 
2891
    t << tmp;
 
2892
    t << "#\n";
 
2893
    tmp = QString("# Revision: %1\n").arg("8"); //if no revision put 8
 
2894
    t << tmp;
 
2895
    t << "# Submitted via: Kscd "KSCDVERSION"\n";
 
2896
    t << "#\n";
 
2897
 
 
2898
 
 
2899
    tmp = "DISCID=";
 
2900
    int counter = 0;
 
2901
 
 
2902
    int num = 0;
 
2903
    for ( QStringList::Iterator it = discidlist.begin();
 
2904
          it != discidlist.end();
 
2905
          ++it, ++num )
 
2906
    {
 
2907
 
 
2908
        tmp += *it;
 
2909
 
 
2910
        if( num < (int) discidlist.count() - 1)
 
2911
        {
 
2912
            if( counter++ == 3 )
 
2913
            {
 
2914
                tmp += "\nDISCID=";
 
2915
                counter = 0;
 
2916
            } else {
 
2917
                tmp += ",";
 
2918
            }
 
2919
        }
 
2920
    }
 
2921
 
 
2922
    tmp += "\n";
 
2923
    t << tmp;
 
2924
 
 
2925
    QStringList returnlist;
 
2926
    QString tmp2;
 
2927
 
 
2928
    tmp2 = *tracktitlelist.at(0);
 
2929
    cddb_encode(tmp2,returnlist);
 
2930
 
 
2931
    if(returnlist.count() == 0)
 
2932
    {
 
2933
        // sanity provision
 
2934
        tmp = QString("DTITLE=%1\n").arg("");
 
2935
        t << tmp;
 
2936
    } else {
 
2937
        for ( QStringList::Iterator it = returnlist.begin();
 
2938
              it != returnlist.end();
 
2939
              ++it )
 
2940
        {
 
2941
            tmp = QString("DTITLE=%1\n").arg(*it);
 
2942
            t << tmp;
 
2943
        }
 
2944
    }
 
2945
 
 
2946
    num = 1;
 
2947
    for ( QStringList::Iterator it = tracktitlelist.begin();
 
2948
          it != tracktitlelist.end();
 
2949
          ++it)
 
2950
    {
 
2951
        tmp2 = *it;
 
2952
        cddb_encode(tmp2,returnlist);
 
2953
 
 
2954
        // no perfect solution, but it's working so far.
 
2955
        if( it != tracktitlelist.begin() ) {
 
2956
            if(returnlist.isEmpty())
 
2957
            {
 
2958
                // sanity provision
 
2959
                tmp = QString("TTITLE%1=%2\n").arg(num-1).arg("");
 
2960
                t << tmp;
 
2961
            } else {
 
2962
                tmp = QString("TTITLE%1=%2\n").arg(num-1).arg(*it);
 
2963
                t << tmp;
 
2964
            }
 
2965
            num++;
 
2966
        }
 
2967
    }
 
2968
 
 
2969
    tmp2 = extlist.first();
 
2970
    cddb_encode(tmp2,returnlist);
 
2971
 
 
2972
    if(returnlist.isEmpty())
 
2973
    {
 
2974
        // sanity provision
 
2975
        tmp = tmp.sprintf("EXTD=%s\n","");
 
2976
        t << tmp;
 
2977
    } else {
 
2978
        for ( QStringList::Iterator it = returnlist.begin();
 
2979
              it != returnlist.end();
 
2980
              ++it )
 
2981
        {
 
2982
            tmp = QString("EXTD=%1\n").arg(*it);
 
2983
            t << tmp;
 
2984
        }
 
2985
    }
 
2986
 
 
2987
    int i = 1;
 
2988
    for ( QStringList::Iterator it = extlist.at(1);
 
2989
          it != extlist.end();
 
2990
          ++it, i++ )
 
2991
    {
 
2992
        tmp2 = *it;
 
2993
        cddb_encode(tmp2,returnlist);
 
2994
 
 
2995
        if(returnlist.count() == 0)
 
2996
        {
 
2997
            // sanity provision
 
2998
            tmp = tmp.sprintf("EXTT%d=%s\n",i-1,"");
 
2999
            t << tmp;
 
3000
        } else {
 
3001
            for(int j = 0; j < (int) returnlist.count();j++)
 
3002
            {
 
3003
                tmp = tmp.sprintf("EXTT%d=%s\n",i-1,(*returnlist.at(j)).utf8().data());
 
3004
                t << tmp;
 
3005
            }
 
3006
        }
 
3007
    }
 
3008
    QString     playorder;
 
3009
    cddb_encode(playorder,returnlist);
 
3010
 
 
3011
    for(int i = 0; i < (int) returnlist.count();i++)
 
3012
    {
 
3013
        tmp = tmp.sprintf("PLAYORDER=%s\n", (*returnlist.at(i)).utf8().data());
 
3014
        t << tmp;
 
3015
    }
 
3016
    t << "\n";
 
3017
 
 
3018
    file.close();
 
3019
    chmod(QFile::encodeName(file.name()), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
 
3020
    return;
 
3021
} // save_cddb_entry
 
3022
 
 
3023
 
 
3024
/**
 
3025
 * main()
 
3026
 */
 
3027
int
 
3028
main( int argc, char *argv[] )
 
3029
{
 
3030
 
 
3031
    KAboutData aboutData( "kscd", I18N_NOOP("kscd"),
 
3032
                          KSCDVERSION, description,
 
3033
                          KAboutData::License_GPL,
 
3034
                          "(c) 2001, Dirk F�rsterling");
 
3035
    aboutData.addAuthor("Bernd Johannes Wuebben",0, "wuebben@kde.org");
 
3036
    aboutData.addAuthor("Dirk F�rsterling",0, "milliByte@gmx.net");
 
3037
 
 
3038
    KCmdLineArgs::init( argc, argv, &aboutData );
 
3039
 
 
3040
    KApplication a;
 
3041
 
 
3042
    kapp->dcopClient()->attach();
 
3043
    kapp->dcopClient()->registerAs("kscd");
 
3044
    kapp->dcopClient()->setDefaultObject("CDPlayer");
 
3045
 
 
3046
    KGlobal::dirs()->addResourceType("cddb",
 
3047
                                     KStandardDirs::kde_default("data") +
 
3048
                                     "kscd/cddb/");
 
3049
 
 
3050
    //  if (a.isRestored())
 
3051
    //    {
 
3052
    //        RESTORE(KSCD);
 
3053
    //    } else {
 
3054
 
 
3055
    KSCD *k = new KSCD();
 
3056
    cur_track = 1;
 
3057
 
 
3058
    bool hide = FALSE;
 
3059
 
 
3060
    for(int i = 0; i < argc; i++)
 
3061
    {
 
3062
        if(strcmp(argv[i],"-hide") == 0)
 
3063
        {
 
3064
            hide = TRUE;
 
3065
        }
 
3066
 
 
3067
        if(strcmp(argv[i],"-h") == 0)
 
3068
        {
 
3069
            printf("KSCD "KSCDVERSION
 
3070
                   "\n Copyright 1997-99 Bernd Johannes Wuebben wuebben@kde.org\n"
 
3071
                   " Copyright 1999-2001 Dirk Foersterling milliByte@gmx.de\n");
 
3072
            printf(i18n("-h: display commandline options\n").local8Bit());
 
3073
            printf(i18n("-d: enable debugging output.\n").local8Bit());
 
3074
            exit(0);
 
3075
        }
 
3076
    }
 
3077
 
 
3078
    a.setTopWidget(k);
 
3079
    a.setMainWidget( k );
 
3080
    k->setCaption(a.caption());
 
3081
    if(!hide)
 
3082
        k->show();
 
3083
    //    }
 
3084
    return a.exec();
 
3085
} // main()
 
3086
 
 
3087
#include "kscd.moc"