summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/printwizard/plugin_printwizard.cpp
blob: 55982b9057037a90f787bb08b1eeaa78f59a6691 (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
/* ============================================================
 * Author: Todd Shoemaker <todd@theshoemakers.net>
 * Date  : 2003-09-30
 * Description :
 *
 * Copyright 2003 by Todd Shoemaker <todd@theshoemakers.net>

 * 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.
 *
 * ============================================================ */

// C Ansi includes

extern "C"
{
#include <unistd.h>
}

// Include files for TQt

#include <tqdir.h>

// Include files for KDE

#include <klocale.h>
#include <kaction.h>
#include <kapplication.h>
#include <kgenericfactory.h>
#include <klibloader.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kstandarddirs.h>
#include <kurl.h>

// Local includes

#include "frmprintwizard.h"
#include "plugin_printwizard.h"
#include "plugin_printwizard.moc"

typedef KGenericFactory<Plugin_PrintWizard> Factory;

K_EXPORT_COMPONENT_FACTORY( kipiplugin_printwizard,
                            Factory("kipiplugin_printwizard"))

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

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

    m_printAction =  new KAction (i18n("Print Wizard..."),
                                  "fileprint",
                                  CTRL+Key_P,
                                  this,
                                  TQT_SLOT(slotActivate()),
                                  actionCollection(),
                                  "printwizard");

    addAction( m_printAction );

    m_interface = dynamic_cast< KIPI::Interface* >( parent() );
        
    if ( !m_interface ) 
    {
       kdError( 51000 ) << "Kipi interface is null!" << endl;
       return;
    }
    
    KIPI::ImageCollection selection = m_interface->currentSelection();
    m_printAction->setEnabled( selection.isValid() &&
                               !selection.images().isEmpty() );

    connect( m_interface, TQT_SIGNAL( selectionChanged( bool ) ), 
             m_printAction, TQT_SLOT( setEnabled( bool ) )  );
}

Plugin_PrintWizard::~Plugin_PrintWizard()
{
}

void Plugin_PrintWizard::slotActivate()
{
    KIPI::ImageCollection album = m_interface->currentSelection();
    
    if ( !album.isValid() )
        return;

    KURL::List fileList = album.images();

    if (fileList.count() == 0)
    {
        KMessageBox::sorry(TQT_TQWIDGET(kapp->activeWindow()), i18n("Please select one or more photos to print."),
                           i18n("Print Wizard"));
        return;
    }

    KIPIPrintWizardPlugin::FrmPrintWizard frm(TQT_TQWIDGET(kapp->activeWindow()));
    KStandardDirs dir;
    TQString tempPath = dir.saveLocation("tmp", "kipi-printwizardplugin-" + TQString::number(getpid()) + "/");
    frm.print(fileList, tempPath);
    frm.exec();
}

KIPI::Category Plugin_PrintWizard::category( KAction* action ) const
{
    if ( action == m_printAction )
       return KIPI::IMAGESPLUGIN;
    
    kdWarning( 51000 ) << "Unrecognized action for plugin category identification" << endl;
    return KIPI::IMAGESPLUGIN; // no warning from compiler, please
}