summaryrefslogtreecommitdiffstats
path: root/src/configpluginspage.cpp
blob: 3fe80ff7a180f511d5cbad575941545b563c600a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639

#include "configpluginspage.h"
#include "configuration.h"
#include "convertpluginloader.h"
#include "replaygainpluginloader.h"
#include "ripperpluginloader.h"

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqcheckbox.h>
// #include <tqevent.h>
// #include <tqdragobject.h>
#include <tqtooltip.h>
#include <tqlocale.h>
// #include <tqurl.h>

#include <tdelocale.h>
#include <kpushbutton.h>
#include <tdeio/job.h>
#include <kstandarddirs.h>
#include <tdemessagebox.h>
#include <kiconloader.h>
#include <tdefiledialog.h>
#include <tdelistbox.h>
//#include <kurl.h>

ConfigPluginsPage::ConfigPluginsPage( Config* _config, TQWidget* parent, const char* name )
    : ConfigPageBase( parent, name )
{
    config = _config;

    // create an icon loader object for loading icons
    TDEIconLoader* iconLoader = new TDEIconLoader();

    TQVBoxLayout* box = new TQVBoxLayout( parent, 0, 6 );

    TQLabel* lPluginsLabel = new TQLabel( i18n("Installed plugins")+":", parent, "lPluginsLabel" );
    box->addWidget( lPluginsLabel );
    TQHBoxLayout* pluginsBox = new TQHBoxLayout( box );
    lPlugins = new TDEListBox( parent, "lPlugins" );
    pluginsBox->addWidget(lPlugins);
    connect( lPlugins, TQ_SIGNAL(highlighted(int)),
               this, TQ_SLOT(pluginsSelectionChanged(int))
             );
    refreshPlugins();

    TQVBoxLayout* pluginsRightBox = new TQVBoxLayout( pluginsBox );
    pAddPlugin = new KPushButton( iconLoader->loadIcon("add",TDEIcon::Small), i18n("Add ..."), parent, "pAddPlugin" );
    pluginsRightBox->addWidget( pAddPlugin );
    connect( pAddPlugin, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(getPlugin())
             );
    pRemovePlugin = new KPushButton( iconLoader->loadIcon("remove",TDEIcon::Small), i18n("Remove"), parent, "pRemovePlugin" );
    pRemovePlugin->setEnabled( false );
    pluginsRightBox->addWidget( pRemovePlugin );
    connect( pRemovePlugin, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(removePlugin())
             );
    pluginsRightBox->addStretch();
    pAboutPlugin = new KPushButton( iconLoader->loadIcon("messagebox_info",TDEIcon::Small), i18n("About"), parent, "pAboutPlugin" );
    pAboutPlugin->setEnabled( false );
    pluginsRightBox->addWidget( pAboutPlugin );
    connect( pAboutPlugin, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(aboutPlugin())
             );
/* NOTE kaligames.de is down
    box->addSpacing( 5 );

    TQLabel* lOnlinePluginsLabel = new TQLabel( i18n("Available plugins")+":", parent, "lOnlinePluginsLabel" );
    box->addWidget( lOnlinePluginsLabel );
    TQHBoxLayout* onlinePluginsBox = new TQHBoxLayout( box );
    lOnlinePlugins = new TDEListBox( parent, "lOnlinePlugins" );
    onlinePluginsBox->addWidget( lOnlinePlugins );
    connect( lOnlinePlugins, TQ_SIGNAL(highlighted(int)),
               this, TQ_SLOT(onlinePluginsSelectionChanged(int))
             );
    TQVBoxLayout* onlinePluginsRightBox = new TQVBoxLayout( onlinePluginsBox );
    pRefreshOnlinePlugins = new KPushButton( iconLoader->loadIcon("reload",TDEIcon::Small), i18n("Refresh"), parent, "pRefreshOnlinePlugins" );
    TQToolTip::add( pRefreshOnlinePlugins, i18n("Download the latest list of available plugins.") );
    onlinePluginsRightBox->addWidget( pRefreshOnlinePlugins );
    connect( pRefreshOnlinePlugins, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(refreshOnlinePlugins())
             );
    // TODO upgrade button
//     pUpgradeOnlinePlugins = new KPushButton( iconLoader->loadIcon("document-save",TDEIcon::Small), i18n("Upgrade"), parent, "pUpgradeOnlinePlugins" );
//     pUpgradeOnlinePlugins->setEnabled( false );
//     TQToolTip::add( pUpgradeOnlinePlugins, i18n("Download all plugins and install them into the soundKonverter directory.") );
//     onlinePluginsRightBox->addWidget( pUpgradeOnlinePlugins );
//     connect(pInstallAllOnlinePlugins,TQ_SIGNAL(clicked()),this,TQ_SLOT(upgradeOnlinePlugins()));
    onlinePluginsRightBox->addStretch();
    pInstallOnlinePlugin = new KPushButton( iconLoader->loadIcon("document-save",TDEIcon::Small), i18n("Install"), parent, "pInstallOnlinePlugin" );
    pInstallOnlinePlugin->setEnabled( false );
    TQToolTip::add( pInstallOnlinePlugin, i18n("Download the selected plugin and install it into the soundKonverter directory.") );
    onlinePluginsRightBox->addWidget( pInstallOnlinePlugin );
    connect( pInstallOnlinePlugin, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(getOnlinePlugin())
             );
    pAboutOnlinePlugin = new KPushButton( iconLoader->loadIcon("messagebox_info",TDEIcon::Small), i18n("About"), parent, "pAboutOnlinePlugin" );
    pAboutOnlinePlugin->setEnabled( false );
    onlinePluginsRightBox->addWidget( pAboutOnlinePlugin );
    connect( pAboutOnlinePlugin, TQ_SIGNAL(clicked()),
               this, TQ_SLOT(aboutOnlinePlugin())
             );
    cCheckOnlinePlugins = new TQCheckBox( i18n("Check for new plugins on every startup"), parent, "cCheckOnlinePlugins" );
    cCheckOnlinePlugins->setChecked( config->data.plugins.checkForUpdates );
    box->addWidget( cCheckOnlinePlugins );
    connect( cCheckOnlinePlugins, TQ_SIGNAL(toggled(bool)),
               this, TQ_SLOT(cfgChanged())
             );

//     box->addStretch();

    // delete the icon loader object
    delete iconLoader;

    if( config->data.plugins.checkForUpdates && config->onlinePluginsChanged ) {
        // NOTE copied from below
        TQString line;
        bool add;
        TQFile file( locateLocal("data","soundkonverter/pluginlist.txt") );
        if( file.open(IO_ReadOnly) ) {
            TQTextStream stream( &file );
            while( !stream.atEnd() ) {
                line = stream.readLine(); // line of text excluding '\n'
                line.replace( "&amp;", "&" );
                line.replace( "&auml;", "ä" );
                line.replace( "&Auml;", "Ä" );
                line.replace( "&ouml;", "ö" );
                line.replace( "&Ouml;", "Ö" );
                line.replace( "&uuml;", "ü" );
                line.replace( "&Uuml;", "Ü" );
                line.replace( "&szlig;", "ß" );

                add = true;
                for( uint i=0; i<lPlugins->count(); i++ ) {
                    if( lPlugins->text(i) == line ) {
                        add = false;
                        break;
                    }
                }
                if( add ) lOnlinePlugins->insertItem( line );
            }
            file.close();
        }
    }
*/
}

ConfigPluginsPage::~ConfigPluginsPage()
{}

void ConfigPluginsPage::resetDefaults()
{
//     cCheckOnlinePlugins->setChecked( false );

//     cfgChanged();
}

void ConfigPluginsPage::saveSettings()
{
//     config->data.plugins.checkForUpdates = cCheckOnlinePlugins->isChecked();
}

void ConfigPluginsPage::pluginsSelectionChanged( int index )
{
    TQString name = lPlugins->text( index );

    TQValueList<ConvertPlugin*> converters = config->allConverters();
    for( TQValueList<ConvertPlugin*>::Iterator it = converters.begin(); it != converters.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFileInfo file( (*it)->filePathName );
            if( file.isWritable() ) pRemovePlugin->setEnabled( true );
            else pRemovePlugin->setEnabled( false );
            break;
        }
    }

    TQValueList<ReplayGainPlugin*> replaygains = config->allReplayGains();
    for( TQValueList<ReplayGainPlugin*>::Iterator it = replaygains.begin(); it != replaygains.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFileInfo file( (*it)->filePathName );
            if( file.isWritable() ) pRemovePlugin->setEnabled( true );
            else pRemovePlugin->setEnabled( false );
            break;
        }
    }

    TQValueList<RipperPlugin*> rippers = config->allRippers();
    for( TQValueList<RipperPlugin*>::Iterator it = rippers.begin(); it != rippers.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFileInfo file( (*it)->filePathName );
            if( file.isWritable() ) pRemovePlugin->setEnabled( true );
            else pRemovePlugin->setEnabled( false );
            break;
        }
    }

    pAboutPlugin->setEnabled( true );
}

void ConfigPluginsPage::refreshPlugins()
{
    lPlugins->clear();

    TQValueList<ConvertPlugin*> converters = config->allConverters();
    for( TQValueList<ConvertPlugin*>::Iterator it = converters.begin(); it != converters.end(); ++it ) {
        lPlugins->insertItem( (*it)->info.name + " v. " + TQString::number((*it)->info.version) );
        //lPlugins->insertItem( i18n("%1, Version: %2").arg((*it)->info.name).arg((*it)->info.version) );
    }

    TQValueList<ReplayGainPlugin*> replaygains = config->allReplayGains();
    for( TQValueList<ReplayGainPlugin*>::Iterator it = replaygains.begin(); it != replaygains.end(); ++it ) {
        lPlugins->insertItem( (*it)->info.name + " v. " + TQString::number((*it)->info.version) );
        //lPlugins->insertItem( i18n("%1, Version: %2").arg((*it)->info.name).arg((*it)->info.version) );
    }

    TQValueList<RipperPlugin*> rippers = config->allRippers();
    for( TQValueList<RipperPlugin*>::Iterator it = rippers.begin(); it != rippers.end(); ++it ) {
        lPlugins->insertItem( (*it)->info.name + " v. " + TQString::number((*it)->info.version) );
        //lPlugins->insertItem( i18n("%1, Version: %2").arg((*it)->info.name).arg((*it)->info.version) );
    }
}

void ConfigPluginsPage::getPlugin()
{
    TQString url = KFileDialog::getOpenFileName( TQDir::homeDirPath(), i18n("*.soundkonverter.xml|Plugins (*.soundkonverter.xml)"), this, i18n("Choose a plugin to add!") );
    if( !url.isEmpty() ) {
        TQString filePathName = KURL::decode_string( url );
        TQString fileName = filePathName.right( filePathName.length() - filePathName.findRev("/") );
        getPluginFilePathName = locateLocal("data","soundkonverter/plugins/") + fileName;
        getPluginJob = TDEIO::file_copy( url, getPluginFilePathName, -1, true, false, false );
        connect( getPluginJob, TQ_SIGNAL(result(TDEIO::Job*)),
                   this, TQ_SLOT(getPluginFinished(TDEIO::Job*))
                 );
    }
}

void ConfigPluginsPage::getPluginFinished( TDEIO::Job* job )
{
    if( job->error() == 0 ) {
        ConvertPluginLoader* convertPluginLoader = new ConvertPluginLoader();
        ReplayGainPluginLoader* replaygainPluginLoader = new ReplayGainPluginLoader();
        RipperPluginLoader* ripperPluginLoader = new RipperPluginLoader();

        if( convertPluginLoader->verifyFile(getPluginFilePathName) == -1 &&
            replaygainPluginLoader->verifyFile(getPluginFilePathName) == -1 &&
            ripperPluginLoader->verifyFile(getPluginFilePathName) == -1 )
        {
            TDEIO::del( getPluginFilePathName, false, false );
            KMessageBox::error( this,
                i18n("The plugin could not be installed. Please ensure that you have selected a valid soundKonverter plugin file."),
                i18n("Error while installing plugin") );
        }
        else
        {
            // TODO reload plugins without restart
//             ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//             if( plugin->info.version != -1 ) {
//                 lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//             }
//             else {
//                 delete plugin;
//                 ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//                 if( plugin->info.version != -1 ) {
//                     lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//                 }
//                 else {
//                     delete plugin;
//                     ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//                     if( plugin->info.version != -1 ) {
//                         lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//                     }
//                 }
//             }
//             delete plugin;
            KMessageBox::information( this,
                i18n("The plugin was installed successfully. Please restart soundKonverter in order to activate it."),
                i18n("Plugin successfully installed") );
            //config->reloadPlugins();
            //refreshPlugins();
            //emit rescanForBackends();
            //emit reloadEnDecoderPage();
        }

        delete convertPluginLoader;
        delete replaygainPluginLoader;
        delete ripperPluginLoader;
    }
    else {
        KMessageBox::error( this,
            i18n("The plugin could not be installed. Please ensure that you have write permission on your whole user directory."),
            i18n("Error while installing plugin") );
    }
}

void ConfigPluginsPage::removePlugin()
{
    // TODO reload plugins without restart

    TQString name = lPlugins->currentText();

    TQValueList<ConvertPlugin*> converters = config->allConverters();
    for( TQValueList<ConvertPlugin*>::Iterator it = converters.begin(); it != converters.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFile file( (*it)->filePathName );
            if( file.remove() ) {
                lPlugins->removeItem( lPlugins->currentItem() );
                KMessageBox::information( this,
                    i18n("The plugin was removed successfully. Please restart soundKonverter in order to deactivate it."),
                    i18n("Plugin successfully removed") );
            }
            else {
                KMessageBox::error( this,
                    i18n("The plugin could not be removed. Please ensure that you have write permission on your whole user directory."),
                    i18n("Error while removing plugin") );
            }
            break;
        }
    }

    TQValueList<ReplayGainPlugin*> replaygains = config->allReplayGains();
    for( TQValueList<ReplayGainPlugin*>::Iterator it = replaygains.begin(); it != replaygains.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFile file( (*it)->filePathName );
            if( file.remove() ) {
                lPlugins->removeItem( lPlugins->currentItem() );
                KMessageBox::information( this,
                    i18n("The plugin was removed successfully. Please restart soundKonverter in order to deactivate it."),
                    i18n("Plugin successfully removed") );
            }
            else {
                KMessageBox::error( this,
                    i18n("The plugin could not be removed. Please ensure that you have write permission on your whole user directory."),
                    i18n("Error while removing plugin") );
            }
            break;
        }
    }

    TQValueList<RipperPlugin*> rippers = config->allRippers();
    for( TQValueList<RipperPlugin*>::Iterator it = rippers.begin(); it != rippers.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            TQFile file( (*it)->filePathName );
            if( file.remove() ) {
                lPlugins->removeItem( lPlugins->currentItem() );
                KMessageBox::information( this,
                    i18n("The plugin was removed successfully. Please restart soundKonverter in order to deactivate it."),
                    i18n("Plugin successfully removed") );
            }
            else {
                KMessageBox::error( this,
                    i18n("The plugin could not be removed. Please ensure that you have write permission on your whole user directory."),
                    i18n("Error while removing plugin") );
            }
            break;
        }
    }

/*    backendPlugins.remove(lPlugins->currentText());
    replayGainPlugins.remove(lPlugins->currentText());
    backendPlugins.reload();
    replayGainPlugins.reload();
    lPlugins->clear();
    lPlugins->insertStringList(backendPlugins.loadedPlugins());
    lPlugins->insertStringList(replayGainPlugins.loadedPlugins());
    emit rescanForBackends();
    emit reloadEnDecoderPage();*/
}

void ConfigPluginsPage::aboutPlugin()
{
    // TODO add link support

    TQString name = lPlugins->currentText();

    TQValueList<ConvertPlugin*> converters = config->allConverters();
    for( TQValueList<ConvertPlugin*>::Iterator it = converters.begin(); it != converters.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            KMessageBox::information( this,
                i18n((*it)->info.about.utf8().data()) + "\n" +
                i18n("Version") + ": " + TQString::number((*it)->info.version) + "\n" +
                i18n("Author") + ": " + (*it)->info.author,
                i18n("About") + ": " + (*it)->info.name );
            break;
        }
    }

    TQValueList<ReplayGainPlugin*> replaygains = config->allReplayGains();
    for( TQValueList<ReplayGainPlugin*>::Iterator it = replaygains.begin(); it != replaygains.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            KMessageBox::information( this,
                i18n((*it)->info.about.utf8().data()) + "\n" +
                i18n("Version") + ": " + TQString::number((*it)->info.version) + "\n" +
                i18n("Author") + ": " + (*it)->info.author,
                i18n("About") + ": " + (*it)->info.name );
            break;
        }
    }

    TQValueList<RipperPlugin*> rippers = config->allRippers();
    for( TQValueList<RipperPlugin*>::Iterator it = rippers.begin(); it != rippers.end(); ++it ) {
        if( name == (*it)->info.name + " v. " + TQString::number((*it)->info.version) ) {
            KMessageBox::information( this,
                i18n((*it)->info.about.utf8().data()) + "\n" +
                i18n("Version") + ": " + TQString::number((*it)->info.version) + "\n" +
                i18n("Author") + ": " + (*it)->info.author,
                i18n("About") + ": " + (*it)->info.name );
            break;
        }
    }
}

void ConfigPluginsPage::onlinePluginsSelectionChanged( int index )
{
    if( lOnlinePlugins->currentText() != i18n("No new plugins available!") ) {
        pInstallOnlinePlugin->setEnabled( true );
        pAboutOnlinePlugin->setEnabled( true );
    }
    else {
        pInstallOnlinePlugin->setEnabled( false );
        pAboutOnlinePlugin->setEnabled( false );
    }
}

void ConfigPluginsPage::refreshOnlinePlugins()
{
    pRefreshOnlinePlugins->setEnabled( false );

    refreshOnlinePluginsJob = TDEIO::file_copy( "http://kaligames.de/downloads/soundkonverter/plugins/download.php?version=" + TQString::number(config->data.app.configVersion),
        locateLocal("data","soundkonverter/pluginlist.txt"), -1, true, false, false );
    connect( refreshOnlinePluginsJob, TQ_SIGNAL(result(TDEIO::Job*)),
               this, TQ_SLOT(refreshOnlinePluginsFinished(TDEIO::Job*))
             );
}

void ConfigPluginsPage::refreshOnlinePluginsFinished( TDEIO::Job* job )
{
    if( job->error() == 0 ) {
        lOnlinePlugins->clear();

        TQString line;
        bool add;
        TQFile file( locateLocal("data","soundkonverter/pluginlist.txt") );
        if( file.open(IO_ReadOnly) ) {
            TQTextStream stream( &file );
            while( !stream.atEnd() ) {
                line = stream.readLine(); // line of text excluding '\n'
                line.replace( "&amp;", "&" );
                line.replace( "&auml;", "ä" );
                line.replace( "&Auml;", "Ä" );
                line.replace( "&ouml;", "ö" );
                line.replace( "&Ouml;", "Ö" );
                line.replace( "&uuml;", "ü" );
                line.replace( "&Uuml;", "Ü" );
                line.replace( "&szlig;", "ß" );

                add = true;
                for( uint i=0; i<lPlugins->count(); i++ ) {
                    if( lPlugins->text(i) == line ) {
                        add = false;
                        break;
                    }
                }
                if( add ) lOnlinePlugins->insertItem( line );
            }
            file.close();
        }

        if( lOnlinePlugins->count() == 0 ) {
            lOnlinePlugins->insertItem( i18n("No new plugins available!") );
        }
    }
    else {
        KMessageBox::error( this,
            i18n("The plugin list could not be downloaded. Please ensure, that your internet connection works correct.\nMaybe our server is busy at the moment, please try it again later."),
            i18n("Error while loading plugin list") );
    }

    pRefreshOnlinePlugins->setEnabled( true );
}

void ConfigPluginsPage::getOnlinePlugin()
{
    pInstallOnlinePlugin->setEnabled( false );
    TQString name;

    for( uint i=0; i<lOnlinePlugins->count(); i++ ) {
        if( lOnlinePlugins->isSelected(i) ) {
            name = lOnlinePlugins->text( i );
            lOnlinePlugins->removeItem( i );
            break;
        }
    }

    name.replace( "&", "&amp;" );
    name.replace( "ä", "&auml;" );
    name.replace( "Ä", "&Auml;" );
    name.replace( "ö", "&ouml;" );
    name.replace( "Ö", "&Ouml;" );
    name.replace( "ü", "&uuml;" );
    name.replace( "Ü", "&Uuml;" );
    name.replace( "ß", "&szlig;" );
    KURL::encode_string( name );
    getOnlinePluginJob = TDEIO::file_copy( "http://kaligames.de/downloads/soundkonverter/plugins/getfile.php?version=" + TQString::number(config->data.app.configVersion) + "&file=" + name,
        locateLocal("data","soundkonverter/plugins/newplugin.xml"), -1, true, false, false );
    connect( getOnlinePluginJob, TQ_SIGNAL(result(TDEIO::Job*)),
               this, TQ_SLOT(getOnlinePluginFinished(TDEIO::Job*))
             );
}

void ConfigPluginsPage::getOnlinePluginFinished( TDEIO::Job* job )
{
    if( job->error() == 0 ) {
        TQString name;
        TQString line;
        TQFile file( locateLocal("data","soundkonverter/plugins/newplugin.xml") );
        if( file.open(IO_ReadOnly) ) {
            TQTextStream stream( &file );
            name = stream.readLine(); // read the file name from the top of the file
            getPluginFilePathName = locateLocal("data","soundkonverter/plugins/") + name;
            TQFile newFile( getPluginFilePathName );
            if( newFile.open(IO_WriteOnly) ) {
                TQTextStream newStream( &newFile );
                while( !stream.atEnd() ) {
                    line = stream.readLine(); // line of text excluding '\n'
                    newStream << line << "\n";
                }
                newFile.close();
            }
            file.close();
        }
        file.remove();

        ConvertPluginLoader* convertPluginLoader = new ConvertPluginLoader();
        ReplayGainPluginLoader* replaygainPluginLoader = new ReplayGainPluginLoader();
        RipperPluginLoader* ripperPluginLoader = new RipperPluginLoader();

        if( convertPluginLoader->verifyFile(getPluginFilePathName) == -1 &&
            replaygainPluginLoader->verifyFile(getPluginFilePathName) == -1 &&
            ripperPluginLoader->verifyFile(getPluginFilePathName) == -1 )
        {
            TDEIO::del( getPluginFilePathName, false, false );
            KMessageBox::error( this,
                i18n("The plugin could not be installed. Please ensure that you have selected a valid soundKonverter plugin file."),
                i18n("Error while installing plugin") );
        }
        else
        {
            // TODO reload plugins without restart
//             ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//             if( plugin->info.version != -1 ) {
//                 lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//             }
//             else {
//                 delete plugin;
//                 ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//                 if( plugin->info.version != -1 ) {
//                     lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//                 }
//                 else {
//                     delete plugin;
//                     ConvertPlugin* plugin = convertPluginLoader->loadFile( getPluginFilePathName );
//                     if( plugin->info.version != -1 ) {
//                         lPlugins->insertItem( plugin->info.name + " v. " + TQString::number(plugin->info.version) + " (" + i18n("restart necessary") + ")" );
//                     }
//                 }
//             }
//             delete plugin;
            KMessageBox::information( this,
                i18n("The plugin was installed successfully. Please restart soundKonverter in order to activate it."),
                i18n("Plugin successfully installed") );
            //config->reloadPlugins();
            //refreshPlugins();
            //emit rescanForBackends();
            //emit reloadEnDecoderPage();
        }

        delete convertPluginLoader;
        delete replaygainPluginLoader;
        delete ripperPluginLoader;
    }
    else {
        KMessageBox::error( this,
            i18n("The plugin could not be installed. Please ensure that you have write permission on your whole user directory."),
            i18n("Error while installing plugin") );
    }
}

void ConfigPluginsPage::aboutOnlinePlugin()
{
    pAboutOnlinePlugin->setEnabled( false );

    TQString name = lOnlinePlugins->currentText();
    name.replace( "&", "&amp;" );
    name.replace( "ä", "&auml;" );
    name.replace( "Ä", "&Auml;" );
    name.replace( "ö", "&ouml;" );
    name.replace( "Ö", "&Ouml;" );
    name.replace( "ü", "&uuml;" );
    name.replace( "Ü", "&Uuml;" );
    name.replace( "ß", "&szlig;" );
    KURL::encode_string( name );
    aboutOnlinePluginJob = TDEIO::file_copy( "http://kaligames.de/downloads/soundkonverter/plugins/info.php?file=" + name + "&lang=" + TQLocale::languageToString(TQLocale::system().language()),
        locateLocal("data","soundkonverter/plugin_info.txt"), -1, true, false, false );
    connect( aboutOnlinePluginJob, TQ_SIGNAL(result(TDEIO::Job*)),
               this, TQ_SLOT(aboutOnlinePluginFinished(TDEIO::Job*))
             );
}

void ConfigPluginsPage::aboutOnlinePluginFinished( TDEIO::Job* job )
{
    if( job->error() == 0 ) {
        TQString name = lOnlinePlugins->currentText();

        TQFile file( locateLocal("data","soundkonverter/plugin_info.txt") );
        if( file.open(IO_ReadOnly) ) {
            TQTextStream stream( &file );
            TQString data = stream.readLine();
            KMessageBox::information( this, i18n(data.utf8().data()), i18n("About") + ": " + name,
                TQString(), KMessageBox::Notify | KMessageBox::AllowLink );
        }
        else {
            KMessageBox::error( this,
                i18n("The plugin info could not be downloaded. Please ensure, that your internet connection works correctly."),
                i18n("Error while loading plugin info") );
        }
    }
    else {
        KMessageBox::error( this,
            i18n("The plugin info could not be downloaded. Please ensure, that your internet connection works correctly."),
            i18n("Error while loading plugin info") );
    }

    pAboutOnlinePlugin->setEnabled( true );
}

#include "configpluginspage.moc"