3
#include <qtextcodec.h>
5
#include <noatun/stdaction.h>
6
#include "htmlexport.h"
10
KDE_EXPORT Plugin *create_plugin()
12
return new HTMLExport();
16
HTMLExport::HTMLExport(): QObject(0, "HTMLExport"), Plugin()
18
NOATUNPLUGINC(HTMLExport);
20
mAction = new KAction(i18n("&Export Playlist..."), "filesaveas", 0,
21
this, SLOT(slotExport()), this, "exportlist");
22
napp->pluginActionMenu()->insert(mAction);
25
config = KGlobal::config();
28
HTMLExport::~HTMLExport()
30
napp->pluginActionMenu()->remove(mAction);
33
void HTMLExport::slotExport()
36
config->setGroup("HTMLExport");
39
KURL url = KFileDialog::getSaveURL(QString::null,
42
i18n("Export Playlist"));
44
// write into tempfile
46
temp.setAutoDelete(true);
47
QFile file(temp.name());
48
file.open(IO_WriteOnly);
49
QTextStream str(&file);
50
str.setCodec(QTextCodec::codecForName("utf8"));
52
str << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
53
str << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">" << endl;
54
str << "<!-- Generated by Noatun " << NOATUN_MAJOR << "." << NOATUN_MINOR << "." << NOATUN_PATCHLEVEL << " -->" << endl;
58
str << "<html>" << endl;
59
str << "<head>" << endl;
60
str << "\t<title>" << i18n("Noatun Playlist") << "</title>" << endl;
62
str << "\t<style type=\"text/css\">" << endl;
63
str << "\t\t<!--" << endl;
64
// Set the heading color
65
str << "\t\th1 { color:#"<< getColorByEntry("headColor")<<"; }" << endl;
67
// Optionally set the background image
68
if (!config->readPathEntry( "bgImgPath" ).stripWhiteSpace().isEmpty()) {
70
str << "\t\tp,li { color:#"<< getColorByEntry("txtColor") << "; }" << endl;
71
str << "\t\tbody { background-image: url(\"" << config->readPathEntry( "bgImgPath" ) << "\"); }" << endl;
75
str << "\t\tp,li,body { color:#"<< getColorByEntry("txtColor");
76
str << "; background-color:#" << getColorByEntry( "bgColor" ) << "; }" << endl;
79
// Links are text colored, too
80
str << "\t\ta { color:#" << getColorByEntry("txtColor") << "; }" << endl;
81
if (getColorByEntry("hoverColor") != getColorByEntry("txtColor"))
82
str << "\t\ta:hover { color:#"<< getColorByEntry("hoverColor")<<"; }"<< endl;
84
str << "\t\t-->" << endl;
85
str << "\t</style>" << endl;
87
str << "</head>" << endl;
89
str << "<body>" << endl;
90
str << "\t<h1>" << i18n("Noatun Playlist") << "</h1>" << endl;
92
// Cache the config settings used in the big loop
93
bool link_entries = config->readBoolEntry( "linkEntries" );
94
bool number_entries = config->readBoolEntry( "numberEntries" );
97
str << "\t\t<ol>" << endl;
99
str << "\t\t<p>" << endl;
102
for (PlaylistItem item = napp->playlist()->getFirst();item;item = napp->playlist()->getAfter(item)) {
109
str << "<a href=\"" << htmlEscape(item.file()) << "\">";
111
str << htmlEscape(item.title());
117
str << "</li>" << endl;
119
str << "<br />" << endl;
123
str << "\t\t</ol>" << endl;
125
str << "\t\t</p>" << endl;
127
str << "\t</body>" << endl;
128
str << "</html>" << endl;
131
// tempfile -> userdefined file
132
KIO::NetAccess::upload(temp.name(), url, 0);
135
QString HTMLExport::htmlEscape(const QString &source) {
136
// Escape characters that need to be escaped
137
QString temp = source;
139
temp.replace( QRegExp("&"), "&" );
140
temp.replace( QRegExp("<"), "<" );
141
temp.replace( QRegExp(">"), ">" );
146
QString HTMLExport::getColorByEntry(QString s)
154
config->setGroup("HTMLExport");
156
c = config->readColorEntry( s );
157
tmp = QString::number( c.red(), 16);
158
if (tmp.length()==1) tmp="0"+tmp;
161
tmp = QString::number( c.green(), 16);
162
if (tmp.length()==1) tmp="0"+tmp;
165
tmp = QString::number( c.blue(), 16);
166
if (tmp.length()==1) tmp="0"+tmp;
172
//////////////////////////////////// Settings ////////////////////////////////////
174
Prefs::Prefs(QObject *parent)
175
: CModule(i18n("Playlist Export"), i18n("Colors & Settings for HTML Export"), "html", parent)
179
KConfig *config = KGlobal::config();
180
config->setGroup("HTMLExport");
182
// Set default values
183
if ( !config->hasKey( "headColor" ) )
184
config->writeEntry( "headColor", QColor( black ) ) ;
186
if ( !config->hasKey( "hoverColor" ) )
187
config->writeEntry( "hoverColor", QColor( black ) );
189
if ( !config->hasKey( "bgColor" ) )
190
config->writeEntry( "bgColor", QColor( white ) ) ;
192
if ( !config->hasKey( "txtColor" ) )
193
config->writeEntry( "txtColor", QColor( black ) );
197
// Draw Stuff and insert Settings
198
QVBoxLayout *top = new QVBoxLayout(this, KDialog::marginHint(),
199
KDialog::spacingHint() );
201
colorBox = new QGroupBox( i18n( "HTML Color Settings" ), this, "colorBox" );
203
bgcolorLabel = new QGridLayout( colorBox, 2, 5,
204
KDialog::marginHint(), KDialog::spacingHint() );
206
headColorSelect = new KColorButton( colorBox, "headColorSelect" );
208
hoverColorSelect = new KColorButton( colorBox, "hoverColorSelect" );
210
bgColorSelect = new KColorButton( colorBox, "bgColorSelect" );
212
txtColorSelect = new KColorButton( colorBox, "txtColorSelect" );
214
txtColorLabel = new QLabel( colorBox, "txtColorLabel" );
215
txtColorLabel->setText( i18n( "Text:" ) );
216
txtColorLabel->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
218
bgColorLabel = new QLabel( colorBox, "bgColorLabel" );
219
bgColorLabel->setText( i18n( "Background:" ) );
220
bgColorLabel->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
222
headColorLabel = new QLabel( colorBox, "headColorLabel" );
223
headColorLabel->setText( i18n( "Heading:" ) );
224
headColorLabel->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
226
hoverColorLabel = new QLabel( colorBox, "hoverColorLabel" );
227
hoverColorLabel->setText( i18n( "Link hover:" ) );
228
hoverColorLabel->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
230
bgcolorLabel->setRowStretch(0, 1);
232
// Makes the spacing nice
233
bgcolorLabel->setColStretch(1, 2);
234
bgcolorLabel->setColStretch(2, 1);
235
bgcolorLabel->setColStretch(4, 2);
237
bgcolorLabel->addWidget( txtColorLabel, 0, 0 );
238
bgcolorLabel->addWidget( txtColorSelect, 0, 1 );
239
bgcolorLabel->addWidget( headColorLabel, 1, 0 );
240
bgcolorLabel->addWidget( headColorSelect, 1, 1 );
241
bgcolorLabel->addWidget( bgColorLabel, 0, 3 );
242
bgcolorLabel->addWidget( bgColorSelect, 0, 4 );
243
bgcolorLabel->addWidget( hoverColorLabel, 1, 3 );
244
bgcolorLabel->addWidget( hoverColorSelect, 1, 4 );
247
// Set up the Background Image frame
248
bgPicBox = new QHGroupBox( i18n( "Background Image"), this, "bgPicBox" );
250
// Set up the URL requestor
251
bgPicPath = new KURLRequester ( bgPicBox, "bgPicPath" );
252
bgPicPath->setShowLocalProtocol(true);
254
// Set up the URL requestor's file dialog
255
bgPicPath->setMode(KFile::File | KFile::ExistingOnly);
256
bgPicPath->setFilter("image/gif image/jpeg image/gif image/png image/svg+xml image/tiff");
258
linkEntries = new QCheckBox( this, "linkEntries" );
259
linkEntries->setText( i18n( "Hyper&link playlist entries to their URL" ) );
260
linkEntries->setTristate( false );
262
numberEntries = new QCheckBox( this, "numberEntries" );
263
numberEntries->setText( i18n( "&Number playlist entries" ) );
264
numberEntries->setTristate( false );
266
top->addWidget( colorBox );
267
top->addWidget( bgPicBox );
268
top->addWidget( linkEntries );
269
top->addWidget( numberEntries );
278
KConfig *config = KGlobal::config();
280
QString bgRealURL = bgPicPath->url();
282
if (bgRealURL[0] == '/')
283
bgRealURL = "file:" + bgRealURL;
285
config->setGroup( "HTMLExport" );
286
config->writeEntry( "bgColor", bgColorSelect->color() );
287
config->writeEntry( "txtColor", txtColorSelect->color() );
288
config->writeEntry( "headColor", headColorSelect->color() );
289
config->writeEntry( "hoverColor", hoverColorSelect->color() );
290
config->writePathEntry( "bgImgPath", bgRealURL );
291
config->writeEntry( "linkEntries", linkEntries->isChecked() );
292
config->writeEntry( "numberEntries", numberEntries->isChecked() );
298
KConfig *config = KGlobal::config();
299
headColorSelect->setColor(config->readColorEntry( "headColor" ) );
300
hoverColorSelect->setColor( config->readColorEntry( "hoverColor" ) );
301
bgColorSelect->setColor( config->readColorEntry( "bgColor" ) );
302
txtColorSelect->setColor( config->readColorEntry( "txtColor" ) );
303
bgPicPath->setURL( config->readPathEntry( "bgImgPath" ) );
304
numberEntries->setChecked( config->readBoolEntry( "numberEntries" ) );
305
linkEntries->setChecked( config->readBoolEntry( "linkEntries" ) );
307
#include "htmlexport.moc"