summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/imageviewer/plugin_viewer.cpp
blob: ec73beb9e76b7ac34a39a2f31043f87663280c41 (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
/***************************************************************************
 *   Copyright (C) 2007 by Markus Leuthold   *
 *   <kusi (+at) forum.titlis.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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.        *
 ***************************************************************************/

// KDE includes
#include <kgenericfactory.h>
#include <tdemessagebox.h>
#include <kurl.h>

// QT includes
#include <tqmessagebox.h>

// kipi includes
#include <libkipi/imageinfo.h>

// local includes
#include "plugin_viewer.h"
#include "viewerwidget.h"

typedef KGenericFactory<Plugin_viewer> Factory;

K_EXPORT_COMPONENT_FACTORY( kipiplugin_viewer,
                            Factory("kipiplugin_viewer"))

Plugin_viewer::Plugin_viewer( TQObject *parent, const char* name, const TQStringList& )
    :KIPI::Plugin::Plugin( Factory::instance(), parent, name )
{
	kdDebug(51001) << "image viewer plugin loaded" << endl;
}

void Plugin_viewer::setup( TQWidget* widget )
{
	KIPI::Plugin::setup( widget );
	
	KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );
	
	if ( !interface ) 
	{
		kdError( 51000 ) << "Kipi interface is null!" << endl;
		return;
	}
	
	actionViewer = new TDEAction (i18n("Image Viewer"),
	                                    "ViewerWidget",
	                                    0, // do never set shortcuts from plugins.
	                                    this,
	                                    TQ_SLOT(slotActivate()),
	                                    actionCollection(),
	                                    "viewer");
	addAction(actionViewer);
	widget=0;
}

KIPI::Category Plugin_viewer::category( TDEAction* action ) const
{
	if ( action == actionViewer ) {
		return KIPI::TOOLSPLUGIN;
	}
	else {
		kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
		return KIPI::TOOLSPLUGIN; // no warning from compiler, please
	}
}





/*!
    \fn Plugin_viewer::slotActivate()
 */
void  Plugin_viewer::slotActivate()
{
	KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );
	
	if ( !interface ) 
	{
		kdError( 51000 ) << "Kipi interface is null!" << endl;
		return;
	}
	
	widget = new KIPIviewer::ViewerWidget(interface);
	
	switch(widget->getOGLstate()) {
		case KIPIviewer::oglOK:
			widget->show();
			break;
			
		case KIPIviewer::oglNoRectangularTexture:
			kdError( 51000 ) << "GL_ARB_texture_rectangle not supported" << endl;
			delete widget;
			TQMessageBox::critical(new TQWidget(),"OpenGL error","GL_ARB_texture_rectangle not supported");
			break;
			
		case KIPIviewer::oglNoContext:
			kdError( 51000 ) << "no OpenGL context found" << endl;
			delete widget;
			TQMessageBox::critical(new TQWidget(),"OpenGL error","no OpenGL context found");
	}
}