summaryrefslogtreecommitdiffstats
path: root/kommander/pluginmanager/mainwindow.cpp
blob: dd196043b77730328ed7de89da75974f8fa53494 (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
/***************************************************************************
  mainwindow.cpp - Kommander plugin manager mainwindow class implementation
                             -------------------
    begin                : Tue Aug 13 09:31:50 EST 2002
    copyright            : (C) 2004 by Marc Britton
    email                : consume@optushome.com.au
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "mainwindow.h"
#include "pluginmanager.h"

#include <tdetoolbar.h>
#include <tdelistbox.h>
#include <tdeconfig.h>
#include <tdefiledialog.h>
#include <klibloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <tdeglobal.h>
#include <kstandarddirs.h>

MainWindow::MainWindow( TQWidget* parent, const char *name, WFlags f )
    : TDEMainWindow( parent, name, f )
{
  TDEToolBar *toolBar = new TDEToolBar( this );
  toolBar->insertButton("document-open", Add, true, i18n("Add") );
  toolBar->insertButton("no", Remove, true, i18n("Remove") );
  toolBar->insertButton("reload", Refresh, true, i18n("Refresh") );
  connect( toolBar, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(toolButton(int)) );

  m_list = new TDEListBox( this );
  setCentralWidget(m_list);
  
  m_pluginManager = new PluginManager;
  m_list->insertStringList(m_pluginManager->items());
}

MainWindow::~MainWindow()
{
  delete m_pluginManager;
}

void MainWindow::toolButton( int id )
{
  switch (id)
  {
    case Add: 
      add();
      break;
    case Remove:
      remove();
      break;
    case Refresh:
      verify();
      break;
  }
}

void MainWindow::add()
{
  TQString libDir = TDEGlobal::dirs()->findResourceDir("lib", "libkommanderplugin");
  TQString plugin = KFileDialog::getOpenFileName(libDir, "lib*", this, 
    i18n("Add Kommander Plugin"));
  add(plugin);
}

void MainWindow::add(const TQString &plugin)
{
  if (!m_pluginManager->add(plugin))
  {
    TQString errMsg = i18n("<qt>Unable to load Kommander plugin<br><b>%1</b></qt>").arg(plugin);
    KMessageBox::error(this, errMsg, i18n("Cannot add plugin"));
  }
  else
    refresh();
}

void MainWindow::remove()
{
  TQString plugin = m_list->currentText();
  if (m_pluginManager->remove(plugin))
    refresh();
}

void MainWindow::refresh()
{
  m_list->clear();
  m_list->insertStringList(m_pluginManager->items()); 
}

void MainWindow::verify()
{
  m_pluginManager->verify();
  refresh();
}

#include "mainwindow.moc"