File: filenameplugincontainer.cpp

package info (click to toggle)
packagesearch 2.10.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,704 kB
  • sloc: cpp: 9,176; perl: 248; makefile: 15; sh: 11
file content (135 lines) | stat: -rw-r--r-- 3,215 bytes parent folder | download | duplicates (8)
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
//
// C++ Implementation: filenameplugincontainer
//
// Description: 
//
//
// Author: Benjamin Mesing <bensmail@gmx.net>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "filenameplugincontainer.h"

#include <qaction.h>
#include <QMainWindow>
#include <qmessagebox.h>
#include <qobject.h>



// NApplication
#include <applicationfactory.h>
#include <runcommand.h>

// NPluign
#include <iprovider.h>
#include "filenameactionplugin.h"
#include "filenameplugin.h"

#include <helpers.h>
#include <globals.h>

using namespace std;

extern "C" 
{ 
	NPlugin::PluginContainer* new_filenameplugin() 
	{
		return new NPlugin::FilenamePluginContainer;; 
	} 
	
	NPlugin::PluginInformation get_pluginInformation()
	{
		return NPlugin::PluginInformation("filenameplugin", toString(NPackageSearch::VERSION), "Benjamin Mesing");
	} 
}


namespace NPlugin 
{

FilenamePluginContainer::FilenamePluginContainer()
{
	addPlugin("FilenamePlugin");
	addPlugin("FilenameActionPlugin");
	_pCommand = 0;
}


FilenamePluginContainer::~FilenamePluginContainer()
{
	unloadAllPlugins();
	delete _pCommand;
}


/////////////////////////////////////////////////////
// Plugin Container Interface
/////////////////////////////////////////////////////

bool FilenamePluginContainer::init(IProvider* pProvider)
{
	BasePluginContainer::init(pProvider, FilenamePluginFactory::getInstance());
	requestPlugin("FilenamePlugin");
	_pFilenameActionPlugin = dynamic_cast<FilenameActionPlugin*>(requestPlugin("FilenameActionPlugin"));
	connect( _pFilenameActionPlugin->qAptFileUpdateAction(), SIGNAL(triggered(bool)), SLOT(onAptFileUpdate()) );
	return true;
}

QString FilenamePluginContainer::title() const
{
	return QObject::tr("Filename Plugins");
}

/////////////////////////////////////////////////////
// Helper Methods
/////////////////////////////////////////////////////


void FilenamePluginContainer::onAptFileUpdate()
{
	provider()->setEnabled(false);
	NApplication::ApplicationFactory* pFac = NApplication::ApplicationFactory::getInstance();
	_pCommand = pFac->getRunCommand("AptFileUpdateProcess");	// get a suitable user interface for the update
	connect(_pCommand, SIGNAL(quit()), SLOT(onAptFileUpdateFinished()) );
	_pCommand->addArgument("/usr/bin/apt-file");
	_pCommand->addArgument("update");
	try 
	{
		if ( !_pCommand->startAsRoot() )
		{
			provider()->reportError( tr("Command not executed"), tr("For an unknwon reason, the command could "
				"not be executed.") );
			delete _pCommand;
			_pCommand = 0;
			provider()->setEnabled(true);
		}
	}
	catch (const NException::RuntimeException& e)
	{
		provider()->reportError(tr("Command not executed"), toQString(e.description()));
		delete _pCommand;
		_pCommand = 0;
		provider()->setEnabled(true);
	}
}

void FilenamePluginContainer::onAptFileUpdateFinished()
{
	if (!_pCommand->processExitedSuccessful())	// if the command was aborted
	{
		provider()->reportWarning(
			tr("Update not successfully completed"), 
			tr("The apt-file update was not completed successfully.<br>"
			"The database might be broken, rerun <tt>apt-file update</tt> to fix this.")
		);
	}
	delete _pCommand;
	_pCommand = 0;
	provider()->setEnabled(true);
}


};