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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
|
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.digikam.org
*
* Date : 2006-04-04
* Description : A KIPI plugin to generate HTML image galleries
*
* Copyright (C) 2006-2010 by Aurelien Gateau <aurelien dot gateau at free.fr>
*
* 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.
*
* ============================================================ */
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
#include "wizard.moc"
// Qt includes
#include <QCheckBox>
#include <QLabel>
// KDE includes
#include <kapplication.h>
#include <kcombobox.h>
#include <kconfigdialogmanager.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klistwidget.h>
#include <klocale.h>
#include <kmenu.h>
#include <ktextbrowser.h>
#include <kurlrequester.h>
#include <ktoolinvocation.h>
#include <kpushbutton.h>
#include <khelpmenu.h>
// KIPI includes
#include <libkipi/imagecollectionselector.h>
#include <libkipi/interface.h>
// Local includes
#include "abstractthemeparameter.h"
#include "galleryinfo.h"
#include "invisiblebuttongroup.h"
#include "kpaboutdata.h"
#include "kpversion.h"
#include "theme.h"
#include "ui_imagesettingspage.h"
#include "ui_outputpage.h"
#include "ui_themepage.h"
#include "ui_themeparameterspage.h"
namespace KIPIHTMLExport
{
class ThemeListBoxItem : public QListWidgetItem
{
public:
ThemeListBoxItem(QListWidget* const list, Theme::Ptr theme)
: QListWidgetItem(theme->name(), list),
mTheme(theme)
{
}
Theme::Ptr mTheme;
};
// ----------------------------------------------------------------------------------------------
template <class Ui_Class>
class WizardPage : public QWidget, public Ui_Class
{
public:
WizardPage(KAssistantDialog* const dialog, const QString& title)
: QWidget(dialog)
{
this->setupUi(this);
layout()->setMargin(0);
mPage = dialog->addPage(this, title);
}
KPageWidgetItem* page() const
{
return mPage;
}
private:
KPageWidgetItem* mPage;
};
// ----------------------------------------------------------------------------------------------
typedef WizardPage<Ui_ThemePage> ThemePage;
typedef WizardPage<Ui_ThemeParametersPage> ThemeParametersPage;
typedef WizardPage<Ui_OutputPage> OutputPage;
class ImageSettingsPage : public WizardPage<Ui_ImageSettingsPage>
{
public:
ImageSettingsPage(KAssistantDialog* const dialog, const QString& title)
: WizardPage<Ui_ImageSettingsPage>(dialog, title)
{
InvisibleButtonGroup* group = new InvisibleButtonGroup(this);
group->setObjectName("kcfg_useOriginalImageAsFullImage");
group->addButton(mSaveImageButton, int(false));
group->addButton(mUseOriginalImageButton, int(true));
}
};
// ----------------------------------------------------------------------------------------------
struct Wizard::Private
{
GalleryInfo* mInfo;
KConfigDialogManager* mConfigManager;
ImageCollectionSelector* mCollectionSelector;
KPageWidgetItem* mCollectionSelectorPage;
ThemePage* mThemePage;
ThemeParametersPage* mThemeParametersPage;
ImageSettingsPage* mImageSettingsPage;
OutputPage* mOutputPage;
QMap<QByteArray, QWidget*> mThemeParameterWidgetFromName;
void initThemePage()
{
KListWidget* listWidget = mThemePage->mThemeList;
Theme::List list=Theme::getList();
Theme::List::ConstIterator it=list.constBegin(), end=list.constEnd();
for (; it!=end; ++it)
{
Theme::Ptr theme = *it;
ThemeListBoxItem* item = new ThemeListBoxItem(listWidget, theme);
if ( theme->internalName()==mInfo->theme() )
{
listWidget->setCurrentItem(item);
}
}
}
void fillThemeParametersPage(Theme::Ptr theme)
{
// Create a new content page
delete mThemeParametersPage->content;
QWidget* content = new QWidget;
mThemeParametersPage->content = content;
mThemeParametersPage->scrollArea->setWidget(mThemeParametersPage->content);
mThemeParametersPage->scrollArea->viewport()->setAutoFillBackground(false);
content->setAutoFillBackground(false);
mThemeParameterWidgetFromName.clear();
// Create layout. We need to recreate it every time, to get rid of
// spacers
QGridLayout* layout = new QGridLayout(content);
layout->setMargin(0);
layout->setSpacing(KDialog::spacingHint());
// Create widgets
Theme::ParameterList parameterList = theme->parameterList();
QString themeInternalName = theme->internalName();
Theme::ParameterList::ConstIterator it = parameterList.constBegin(),
end = parameterList.constEnd();
for (; it!=end; ++it)
{
AbstractThemeParameter* themeParameter = *it;
QByteArray internalName = themeParameter->internalName();
QString value = mInfo->getThemeParameterValue(
themeInternalName,
internalName,
themeParameter->defaultValue());
QString name = themeParameter->name();
name = i18nc("'%1' is a label for a theme parameter", "%1:", name);
QLabel* label = new QLabel(name, content);
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
QWidget* widget = themeParameter->createWidget(content, value);
label->setBuddy(widget);
int row = layout->rowCount();
layout->addWidget(label, row, 0);
if (widget->sizePolicy().expandingDirections() & Qt::Horizontal)
{
// Widget wants full width
layout->addWidget(widget, row, 1, 1, 2);
}
else
{
// Widget doesn't like to be stretched, add a spacer next to it
layout->addWidget(widget, row, 1);
QSpacerItem* spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum);
layout->addItem(spacer, row, 2);
}
mThemeParameterWidgetFromName[internalName] = widget;
}
// Add spacer at the end, so that widgets aren't spread on the whole
// parent height
QSpacerItem* spacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding);
layout->addItem(spacer, layout->rowCount(), 0);
}
};
Wizard::Wizard(QWidget* const parent, GalleryInfo* const info)
: KPWizardDialog(parent)
{
d = new Private;
d->mInfo = info;
setCaption(i18n("Export image collections to HTML pages"));
// ---------------------------------------------------------------
// About data and help button.
KPAboutData* about = new KPAboutData(
ki18n("HTML Export"),
QByteArray(),
KAboutData::License_GPL,
ki18n("A KIPI plugin to export image collections to HTML pages"),
ki18n("(c) 2006-2009, Aurelien Gateau\n"
"(c) 2010, Gianluca Urgese"));
about->addAuthor(
ki18n("Gianluca Urgese"),
ki18n("Maintainer"),
"giasone.82@gmail.com");
about->addAuthor(
ki18n("Aurelien Gateau"),
ki18n("Former Author and Maintainer"),
"agateau@kde.org");
about->setHandbookEntry("htmlexport");
setAboutData(about);
// ---------------------------------------------------------------
d->mCollectionSelector = iface()->imageCollectionSelector(this);
d->mCollectionSelectorPage = addPage(d->mCollectionSelector, i18n("Collection Selection"));
updateCollectionSelectorPageValidity();
connect(d->mCollectionSelector, SIGNAL(selectionChanged()),
this, SLOT(updateCollectionSelectorPageValidity()));
d->mThemePage = new ThemePage(this, i18n("Theme"));
d->initThemePage();
connect(d->mThemePage->mThemeList, SIGNAL(itemSelectionChanged()),
this, SLOT(slotThemeSelectionChanged()) );
d->mThemeParametersPage = new ThemeParametersPage(this, i18n("Theme Parameters"));
d->mImageSettingsPage = new ImageSettingsPage(this, i18n("Image Settings"));
d->mOutputPage = new OutputPage(this, i18n("Output"));
d->mOutputPage->kcfg_destUrl->setMode(KFile::Directory);
connect(d->mOutputPage->kcfg_destUrl, SIGNAL(textChanged(QString)),
this, SLOT(updateFinishPageValidity()) );
d->mConfigManager = new KConfigDialogManager(this, d->mInfo);
d->mConfigManager->updateWidgets();
// Set page states
// Pages can only be disabled after they have *all* been added!
slotThemeSelectionChanged();
updateFinishPageValidity();
}
Wizard::~Wizard()
{
delete d;
}
void Wizard::updateFinishPageValidity()
{
setValid(d->mOutputPage->page(), !d->mOutputPage->kcfg_destUrl->url().isEmpty());
}
void Wizard::updateCollectionSelectorPageValidity()
{
setValid(d->mCollectionSelectorPage, !d->mCollectionSelector->selectedImageCollections().empty());
}
void Wizard::slotThemeSelectionChanged()
{
KListWidget* listWidget = d->mThemePage->mThemeList;
KTextBrowser* browser = d->mThemePage->mThemeInfo;
if (listWidget->currentItem())
{
Theme::Ptr theme=static_cast<ThemeListBoxItem*>(listWidget->currentItem())->mTheme;
QString url = theme->authorUrl();
QString author = theme->authorName();
bool allowNonsquareThumbnails=theme->allowNonsquareThumbnails();
if (!url.isEmpty())
{
author=QString("<a href='%1'>%2</a>").arg(url).arg(author);
}
QString preview = theme->previewUrl();
QString image = "";
if (!preview.isEmpty())
{
image=QString("<img src='%1/%2' /><br/><br/>").arg(theme->directory(), theme->previewUrl());
}
QString txt=
image +
QString("<b>%3</b><br/><br/>%4<br/><br/>").arg(theme->name(), theme->comment())
+ i18n("Author: %1", author);
browser->setHtml(txt);
setValid(d->mThemePage->page(), true);
// Enable theme parameter page if there is any parameter
Theme::ParameterList parameterList = theme->parameterList();
setAppropriate(d->mThemeParametersPage->page(), parameterList.size() > 0);
d->mImageSettingsPage->kcfg_thumbnailSquare->setEnabled(allowNonsquareThumbnails);
if (!allowNonsquareThumbnails)
d->mImageSettingsPage->kcfg_thumbnailSquare->setChecked(true);
d->fillThemeParametersPage(theme);
}
else
{
browser->clear();
setValid(d->mThemePage->page(), false);
}
}
/**
* Update mInfo
*/
void Wizard::accept()
{
d->mInfo->mCollectionList=d->mCollectionSelector->selectedImageCollections();
Theme::Ptr theme = static_cast<ThemeListBoxItem*>(d->mThemePage->mThemeList->currentItem())->mTheme;
QString themeInternalName = theme->internalName();
d->mInfo->setTheme(themeInternalName);
Theme::ParameterList parameterList = theme->parameterList();
Theme::ParameterList::ConstIterator it = parameterList.constBegin(),
end = parameterList.constEnd();
for (; it!=end; ++it)
{
AbstractThemeParameter* themeParameter = *it;
QByteArray parameterInternalName = themeParameter->internalName();
QWidget* widget = d->mThemeParameterWidgetFromName[parameterInternalName];
QString value = themeParameter->valueFromWidget(widget);
d->mInfo->setThemeParameterValue(
themeInternalName,
parameterInternalName,
value);
}
d->mConfigManager->updateSettings();
KAssistantDialog::accept();
}
} // namespace KIPIHTMLExport
|