summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpluginsettings.cpp
blob: 6b6611f260d077aeb0574a3b295242f535b2626d (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
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2003 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  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 "pmpluginsettings.h"

#include "pmpluginmanager.h"

#include <qlayout.h>
#include <qgroupbox.h>
#include <qlistview.h>
#include <qpushbutton.h>
#include <klocale.h>

class PMPluginListViewItem : public QListViewItem
{
public:
   PMPluginListViewItem( QListView* parent, PMPluginInfo* info )
         : QListViewItem( parent, info->name( ), info->description( ) )
   {
      m_info = info;
      m_enabled = info->enabled( );
      setStatus( );
   }
   void toggleStatus( )
   {
      m_enabled = !m_enabled;
      setStatus( );
   }
   void setStatus( )
   {
      if( m_enabled )
         setText( 2, i18n( "loaded" ) );
      else
         setText( 2, i18n( "deactivated" ) );
   }
   PMPluginInfo* m_info;
   bool m_enabled;
};

PMPluginSettings::PMPluginSettings( QWidget* parent, const char* name )
      : PMSettingsDialogPage( parent, name )
{
   QVBoxLayout* vlayout = new QVBoxLayout( this, 0, KDialog::spacingHint( ) );

   QGroupBox* gb = new QGroupBox( i18n( "Installed Plugins" ), this );
   vlayout->addWidget( gb );

   QVBoxLayout* gvl = new QVBoxLayout( gb, KDialog::marginHint( ), KDialog::spacingHint( ) );
   gvl->addSpacing( 10 );

   m_pPluginsList = new QListView( gb );
   connect( m_pPluginsList, SIGNAL( selectionChanged( ) ),
            SLOT( slotSelectionChanged( ) ) );
   m_pPluginsList->addColumn( i18n( "Name" ) );
   m_pPluginsList->addColumn( i18n( "Description" ) );
   m_pPluginsList->addColumn( i18n( "Status" ) );
   gvl->addWidget( m_pPluginsList, 1 );

   QHBoxLayout* hl = new QHBoxLayout( gvl );
   m_pToggle = new QPushButton( i18n( "Load" ), gb );
   m_pToggle->setEnabled( false );
   connect( m_pToggle, SIGNAL( clicked( ) ), SLOT( slotToggle( ) ) );
   hl->addWidget( m_pToggle );
   hl->addStretch( 1 );

   vlayout->addStretch( 1 );
}

void PMPluginSettings::displaySettings( )
{
   QPtrList<PMPluginInfo> plugins = PMPluginManager::theManager( )->plugins( );
   QPtrListIterator<PMPluginInfo> it( plugins );

   m_pPluginsList->clear( );
   for( ; *it; ++it )
      new PMPluginListViewItem( m_pPluginsList, *it );
}

void PMPluginSettings::applySettings( )
{
   bool changes = false;
   PMPluginListViewItem* item =
      ( PMPluginListViewItem* ) m_pPluginsList->firstChild( );
   for( ; item; item = ( PMPluginListViewItem* ) item->nextSibling( ) )
   {
      if( item->m_enabled != item->m_info->enabled( ) )
      {
         item->m_info->enable( item->m_enabled );
         changes = true;
      }
   }
   if( changes )
      PMPluginManager::theManager( )->updatePlugins( );
}

bool PMPluginSettings::validateData( )
{
   return true;
}

void PMPluginSettings::displayDefaults( )
{
}

void PMPluginSettings::slotToggle( )
{
   PMPluginListViewItem* item =
      ( PMPluginListViewItem* ) m_pPluginsList->currentItem( );
   if( item )
   {
      item->toggleStatus( );
   
      if( item->m_enabled )
         m_pToggle->setText( i18n( "Deactivate" ) );
      else
         m_pToggle->setText( i18n( "Load" ) );
   }
}

void PMPluginSettings::slotSelectionChanged( )
{
   PMPluginListViewItem* item =
      ( PMPluginListViewItem* ) m_pPluginsList->currentItem( );
   if( item )
   {
      m_pToggle->setEnabled( true );
      if( item->m_enabled )
         m_pToggle->setText( i18n( "Deactivate" ) );
      else
         m_pToggle->setText( i18n( "Load" ) );
   }
   else
      m_pToggle->setEnabled( false );
}

#include "pmpluginsettings.moc"