summaryrefslogtreecommitdiffstats
path: root/kview/photobook/photobook.cpp
blob: 8503188dbe49aab10313a9e4f851bd5e6f7c4e3b (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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*
Copyright (c) 2004,2005 Charles Samuels <charles@kde.org>

  This file is hereby licensed under the GNU General Public License version
  2 or later at your option.

  This file is licensed under the TQt Public License version 1 with the
  condition that the licensed will be governed under the Laws of California
  (USA) instead of Norway.  Disputes will be settled in Santa Clara county
  courts.

  This file is licensed under the following additional license.  Be aware
  that it is identical to the BSD license, except for the added clause 3:

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions
 are met:

 1. Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
 3. By integrating this software into any other software codebase, you waive
    all rights to any patents associated with the stated codebase.

 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include "photobook.h"

#include <kparts/componentfactory.h>
#include <kaction.h>
#include <kstdaccel.h>
#include <kstandarddirs.h>

Previews::Previews(PhotoBook *tqparent, const TQStringList &mimetypes)
	: KFileIconView(tqparent, 0)
{
	mPhotoBook = tqparent;
	mMimeTypes = mimetypes;

	connect(&mDirLister, TQT_SIGNAL(clear()), TQT_SLOT(slotClearView()));
	connect(&mDirLister, TQT_SIGNAL(completed()), TQT_SLOT(doneListing()));
	connect(
			&mDirLister, TQT_SIGNAL(newItems(const KFileItemList &)),
			TQT_SLOT(insertNewFiles(const KFileItemList &))
		);
	connect(
			signaler(), TQT_SIGNAL(fileSelected(const KFileItem*)),
			TQT_SLOT(open(const KFileItem*))
		);
	connect(
			&mDirLister, TQT_SIGNAL(deleteItem(KFileItem *)),
			TQT_SLOT(removeItem(KFileItem *))
		);
	
	connect(
			&mDirLister, TQT_SIGNAL( refreshItems( const KFileItemList& ) ),
			TQT_SLOT( slotRefreshItems( const KFileItemList& ) )
		);
	
	setFixedWidth(128);
}

Previews::~Previews()
{

}


void Previews::slotRefreshItems( const KFileItemList& items )
{
	KFileItemListIterator it( items );
	for ( ; it.current(); ++it )
		updateView( it.current() );
}

void Previews::slotClearView()
{
	clearView();
}


void Previews::insertNewFiles(const KFileItemList &items)
{
	addItemList(items);
}

void Previews::removeItem(KFileItem *item)
{
	KFileIconView::removeItem(item);
}


void Previews::go(const KFileItem *k)
{
	setSelected(k, true);
	setCurrentItem(k);
	ensureItemVisible(k);
	open(k);
	updateButton();
}

void Previews::updateButton()
{
	mPhotoBook->updateButton( ( nextItem(currentFileItem())!=0L ), ( prevItem(currentFileItem())!=0L ));
}

void Previews::openURL(const KURL &url)
{
	mDirLister.setMimeFilter(mMimeTypes);
	mDirLister.openURL(url);
}

void Previews::open(const KFileItem *item)
{
	if (!item->isDir())
	{
		const KURL &u = item->url();
		emit open(u);
		updateButton();
	}
}

void Previews::doneListing()
{
	// eep! -- this should not be necessary
	TQTimer::singleShot(0, this, TQT_SLOT(goToFirst()));
}

void Previews::goToFirst()
{
	if (firstFileItem())
		go(firstFileItem());
	else
		updateButton();
}



PhotoBook::PhotoBook(TQWidget *tqparent, PhotoBookPart *part, const char *name)
	: TQSplitter(tqparent, name)
{
	
	TQStringList mimetypes;
	
	KTrader::OfferList offers = KTrader::self()->query(
			"KImageViewer/Viewer", "KParts/ReadOnlyPart",
			"DesktopEntryName == 'kviewviewer'", TQString()
		);

	for (
			KTrader::OfferList::Iterator i(offers.begin());
			i != offers.end(); ++i
		)
	{
		KService::Ptr service = *i;
		mViewer = KParts::ComponentFactory::
			createPartInstanceFromService<KParts::ReadOnlyPart>( service, this, 0, TQT_TQOBJECT(this) );
		
		// is this the correct way to get the supported mimetypes?
		if (mViewer)
		{
			KSimpleConfig e(locate("services", service->desktopEntryPath()));
			e.setGroup("Desktop Entry");
			mimetypes = TQStringList::split(';', e.readEntry("MimeType"));
			break;
		}
	}
		
	
	mList = new Previews(this, mimetypes);

	mFit = mViewer->action("fittowin");

	connect(mList, TQT_SIGNAL(open(const KURL&)), mViewer, TQT_SLOT(openURL(const KURL&)));
	connect(mViewer, TQT_SIGNAL(completed()), mFit, TQT_SLOT(activate()));

	part->insertChildClient(mViewer);
}

void PhotoBook::openURL(const KURL &url)
{
	mList->openURL(url);
	mList->setIgnoreMaximumSize();
	mList->showPreviews();
}

void PhotoBook::next()
{
	KFileItem *k = mList->nextItem(mList->currentFileItem());
	if (k)
		mList->go(k);
}

void PhotoBook::previous()
{
	KFileItem *k = mList->prevItem(mList->currentFileItem());
	if (k)
		mList->go(k);
}


void PhotoBook::updateButton( bool nextExist, bool previousExit)
{
	emit emitUpdateButton( nextExist, previousExit );
}

K_EXPORT_COMPONENT_FACTORY(libphotobook, PhotoBookFactory )

PhotoBookPart::PhotoBookPart(
		TQWidget *parentWidget, const char *widgetName,
		TQObject *tqparent, const char *name,
		const TQStringList&
	)
	: KParts::ReadOnlyPart(tqparent, name)
{
	setInstance(PhotoBookFactory::instance());

	new PhotoBookBrowserExtension(this);
	bv = new PhotoBook(parentWidget, this, widgetName);
	setWidget(bv);

	connect(
			bv, TQT_SIGNAL(emitUpdateButton(bool, bool)),
			this, TQT_SLOT(slotUpdateButton(bool, bool))
		);
	m_pNextAction = KStdAction::next(TQT_TQOBJECT(bv), TQT_SLOT(next()), actionCollection(), "next");
	m_pPreviousAction = KStdAction::prior(TQT_TQOBJECT(bv), TQT_SLOT(previous()), actionCollection(), "previous");

	setXMLFile( "photobookui.rc" );

}

PhotoBookPart::~PhotoBookPart()
{

}


void PhotoBookPart::slotUpdateButton( bool nextExit, bool previousExit)
{
	m_pPreviousAction->setEnabled( previousExit );
	m_pNextAction->setEnabled( nextExit );
}

bool PhotoBookPart::openURL(const KURL &url)
{
	bv->openURL(url);
	return true;
}


KAboutData* PhotoBookPart::createAboutData()
{
	return new KAboutData(
			"photobook", I18N_NOOP("Photo Book"),
			"1.0", I18N_NOOP("Easily browse a folder of photographs"),
			KAboutData::License_GPL,
			I18N_NOOP("Copyright (c) 2004,2005 Charles Samuels <charles@kde.org>")
		);
}

bool PhotoBookPart::openFile()
{
	return true;
}



PhotoBookBrowserExtension::PhotoBookBrowserExtension(PhotoBookPart *p)
	: KParts::BrowserExtension(p, "PhotoBookBrowserExtension")
{

}




#include "photobook.moc"