summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/wallpaper/plugin_wallpaper.cpp
blob: 576ac4890c1cfa98ff02b45dd6cd28d30a8a703e (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* ============================================================
 * File   : plugin_wallpaper.cpp
 *
 * Authors: Gregory KOKANOSKY <gregory dot kokanosky at free.fr>
 *          Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * Date   : 01/2004
 *
 * Description : Set Wall paper plugin for KIPI
 *
 * Copyright 2004 by Gregory KOKANOSKY <gregory dot kokanosky at free.fr>
 * Copyright 2004 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 KDE

 #include <klocale.h>
 #include <kaction.h>
 #include <kgenericfactory.h>
 #include <klibloader.h>
 #include <kconfig.h>
 #include <kdebug.h>
 #include <tdeversion.h>
 #include <krun.h>
 #include <kapplication.h>
 #include <kmessagebox.h>
 #include <ktextbrowser.h>
 #include <tdeversion.h>
 #include <kfiledialog.h>
 #include <kio/netaccess.h>

// KIPI includes

 #include <libkipi/interface.h>
 #include <libkipi/imagecollection.h>

// Local includes

 #include "plugin_wallpaper.h"

typedef KGenericFactory<Plugin_WallPaper> Factory;

K_EXPORT_COMPONENT_FACTORY( kipiplugin_wallpaper,
                            Factory("kipiplugin_wallpaper"))

 /////////////////////////////////////////////////////////////////////////////////////////////////////

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

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

    m_action_Background = new KActionMenu(i18n("&Set as Background"),
                         actionCollection(),
                         "images2desktop");

    m_action_Background->insert(new KAction (i18n("Centered"),
                         0,
                         this,
                         TQT_SLOT(slotSetCenter()),
                         actionCollection(),
                         "images2desktop_center"));

    m_action_Background->insert(new KAction (i18n("Tiled"),
                         0,
                         this,
                         TQT_SLOT(slotSetTiled()),
                         actionCollection(),
                         "images2desktop_tiled"));

    m_action_Background->insert(new KAction (i18n("Centered Tiled"),
                         0,
                         this,
                         TQT_SLOT(slotSetCenterTiled()),
                         actionCollection(),
                         "images2desktop_center_tiled"));

    m_action_Background->insert(new KAction (i18n("Centered Max-Aspect"),
                         0,
                         this,
                         TQT_SLOT(slotSetCenteredMaxpect()),
                         actionCollection(),
                         "images2desktop_center_maxpect"));

    m_action_Background->insert(new KAction (i18n("Tiled Max-Aspect"),
                         0,
                         this,
                         TQT_SLOT(slotSetTiledMaxpect()),
                         actionCollection(),
                         "images2desktop_tiled_maxpect"));

    m_action_Background->insert(new KAction (i18n("Scaled"),
                         0,
                         this,
                         TQT_SLOT(slotSetScaled()),
                         actionCollection(),
                         "images2desktop_scaled"));

    m_action_Background->insert(new KAction (i18n("Centered Auto Fit"),
                         0,
                         this,
                         TQT_SLOT(slotSetCenteredAutoFit()),
                         actionCollection(),
                         "images2desktop_centered_auto_fit"));

    //The Scale & crop code was available from Beta1 on
    #if KDE_IS_VERSION(3,3,91)
    m_action_Background->insert(new KAction (i18n("Scale && Crop"),
			 0,
			 this,
			 TQT_SLOT(slotSetScaleAndCrop()),
			 actionCollection(),
			 "images2desktop_scale_and_crop"));

   #endif
    
    addAction( m_action_Background );

    KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );

    if ( !interface )
           {
           kdError( 51000 ) << "Kipi interface is null!" << endl;
           return;
           }

    KIPI::ImageCollection selection = interface->currentSelection();
    m_action_Background->setEnabled( selection.isValid() );

    connect( interface, TQT_SIGNAL(selectionChanged(bool)),
             m_action_Background, TQT_SLOT(setEnabled(bool)));
 }


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetCenter()
{
   return setWallpaper(CENTER);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetTiled()
{
   return setWallpaper(TILED);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetCenterTiled()
{
   return  setWallpaper(CENTER_TILED);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetCenteredMaxpect()
{
   return setWallpaper(CENTER_MAXPECT);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetTiledMaxpect()
{
   return setWallpaper(TILED_MAXPECT);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetScaled()
{
   return setWallpaper(SCALED);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetCenteredAutoFit()
{
   return setWallpaper(CENTERED_AUTOFIT);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::slotSetScaleAndCrop()
{
   return setWallpaper(SCALE_AND_CROP);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////

void Plugin_WallPaper::setWallpaper(int tqlayout)
{
   if (tqlayout>SCALE_AND_CROP || tqlayout < CENTER)
      return;

   KIPI::Interface* interface = dynamic_cast<KIPI::Interface*>( parent() );

   if ( !interface )
           {
           kdError( 51000 ) << "Kipi interface is null!" << endl;
           return;
           }

   KIPI::ImageCollection images = interface->currentSelection();

   if (!images.isValid() ) return;

   KURL url=images.images()[0];
   TQString path;
   if (url.isLocalFile())
      {
      path=url.path();
      }
   else
      {
      // PENDING We need a way to get a parent widget
      // Sun, 06 Jun 2004 - Aur�ien

      KMessageBox::information( TQT_TQWIDGET(kapp->activeWindow()), i18n(
         "<qt><p>You selected a remote image. It needs to be saved to your local disk to be used as a wallpaper."
         "</p><p>You will now be asked where to save the image.</p></qt>"));
      path = KFileDialog::getSaveFileName(url.fileName(), TQString(), TQT_TQWIDGET(kapp->activeWindow()));

      if (path.isNull()) return;
#if TDE_VERSION > 0x30200
      KIO::NetAccess::download(url, path, 0L);
#else
      KIO::NetAccess::download(url, path);
#endif
      }

   TQString cmd = TQString("dcop kdesktop KBackgroundIface setWallpaper '%1' %2")
                         .tqarg(path).tqarg(tqlayout);

   KRun::runCommand(cmd);
}


/////////////////////////////////////////////////////////////////////////////////////////////////////

KIPI::Category  Plugin_WallPaper::category( KAction* action ) const
{
    if ( action == m_action_Background )
       return KIPI::IMAGESPLUGIN;

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

#include "plugin_wallpaper.moc"