summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/acquireimages/plugin_acquireimages.cpp
blob: 7895593a5b2e1f59141f3ab354acf7df12994f63 (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
/* ============================================================
 *
 * This file is a part of kipi-plugins project
 * http://www.kipi-plugins.org
 *
 * Date        : 2003-10-01
 * Description : a plugin to acquire images
 *
 * Copyright (C) 2003-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * 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, 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.
 * 
 * ============================================================ */

// Include files for TQt

#include <tqimage.h>

// Include files for KDE

#include <klocale.h>
#include <kaction.h>
#include <kgenericfactory.h>
#include <klibloader.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kinstance.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <ktempfile.h>
#include <kscan.h>
#include <kapplication.h>

// Local includes

#include "screenshotdialog.h"
#include "acquireimagedialog.h"
#include "plugin_acquireimages.h"
#include "plugin_acquireimages.moc"

typedef KGenericFactory<Plugin_AcquireImages> Factory;

K_EXPORT_COMPONENT_FACTORY( kipiplugin_acquireimages,
                            Factory("kipiplugin_acquireimages"))

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

void Plugin_AcquireImages::setup( TQWidget* widget )
{
    KIPI::Plugin::setup( widget );

    m_action_scanimages = new KAction (i18n("Scan Images..."),         // Menu message.
                                            "scanner",                 // Menu icon.
                                            0,                         // default shortcut.
                                            this,
                                            TQT_SLOT(slotActivate()),
                                            actionCollection(),
                                            "scan_images");

    m_action_screenshotimages =  new KAction (i18n("Screenshot..."),   // Menu message.
                                            "ksnapshot",               // Menu icon.
                                            0,                         // default shortcut.
                                            this,
                                            TQT_SLOT(slotActivate()),
                                            actionCollection(),
                                            "screenshot_images");

    addAction( m_action_scanimages );
    addAction( m_action_screenshotimages );
}

Plugin_AcquireImages::~Plugin_AcquireImages()
{
}

void Plugin_AcquireImages::slotActivate()
{
    KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );
        
    if ( !interface ) 
    {
        kdError( 51000 ) << "Kipi interface is null!" << endl;
        return;
    }
        
    TQString from(TQT_TQOBJECT(const_cast<TQT_BASE_OBJECT_NAME*>(sender()))->name());
    
    if (from == "scan_images")
    {
        m_scanDialog = KScanDialog::getScanDialog(TQT_TQWIDGET(kapp->activeWindow()), "KIPI Scan Images Plugin");
    
        if ( m_scanDialog )
        {
            m_scanDialog->setMinimumSize(400, 300);
        
            connect(m_scanDialog, TQT_SIGNAL(finalImage(const TQImage &, int)),
                    this, TQT_SLOT(slotAcquireImageDone(const TQImage &)));
        }
        else
        {
            KMessageBox::sorry(TQT_TQWIDGET(kapp->activeWindow()), i18n("No TDE scan-service available; check your system."),
                                i18n("KIPI's 'Scan Images' Plugin"));
            kdDebug ( 51000 ) << "No Scan-service available, aborting!" << endl;
            return;
        }
    
        if ( m_scanDialog->setup() )
            m_scanDialog->show();
    }
    else if (from == "screenshot_images")
    {
        m_screenshotDialog = new KIPIAcquireImagesPlugin::ScreenGrabDialog(interface,
            TQT_TQWIDGET(kapp->activeWindow()), "KIPI ScreenshotImagesDialog");
        m_screenshotDialog->show();
    }
    else
    {
        kdWarning( 51000 ) << "The impossible happened... unknown flip specified" << endl;
        return;
    }
}

void Plugin_AcquireImages::slotAcquireImageDone(const TQImage &img)
{
    //FIXME: this is not a cleaned way to test if scan has been interrupted
    //       anyway it prevents a crash
    TQImage * pImg = (TQImage*)&img;
    if (!pImg )
    {
        kdError(51000) << "Acquired image is null!" << endl;
        return;
    }
    
    KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );
        
    if ( !interface ) 
    {
        kdError( 51000 ) << "Kipi interface is null!" << endl;
        return;
    }
            
    m_acquireImageDialog = new KIPIAcquireImagesPlugin::AcquireImageDialog( interface, TQT_TQWIDGET(kapp->activeWindow()), img);
    m_acquireImageDialog->setMinimumWidth(400);
    m_acquireImageDialog->exec();
}

KIPI::Category Plugin_AcquireImages::category( KAction* action ) const
{
    if ( action == m_action_scanimages )
       return KIPI::IMPORTPLUGIN;
    else if ( action == m_action_screenshotimages )
       return KIPI::IMPORTPLUGIN;

    kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
    return KIPI::IMPORTPLUGIN; // no warning from compiler, please   
}