delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / phonon / kcm / xine / xineoptions.cpp
blobd3fc08b9c2c83d796ad24102ef0cd31f3908ab0a
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2
6 as published by the Free Software Foundation.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 02110-1301, USA.
20 #include "xineoptions.h"
21 #include <kgenericfactory.h>
22 #include <kconfiggroup.h>
24 #include <xine.h>
25 #include <QtDBus/QDBusConnection>
26 #include <QtDBus/QDBusInterface>
28 K_PLUGIN_FACTORY(XineOptionsFactory, registerPlugin<XineOptions>(); )
29 K_EXPORT_PLUGIN(XineOptionsFactory("kcm_phononxine"))
31 XineOptions::XineOptions(QWidget *parent, const QVariantList &args)
32 : KCModule(XineOptionsFactory::componentData(), parent, args), m_noDeinterlace(false)
34 setupUi(this);
36 m_config = KSharedConfig::openConfig("xinebackendrc");
38 connect(deinterlaceMediaList, SIGNAL(clicked(const QModelIndex &)), SLOT(changed()));
39 connect(deinterlaceMethodBox, SIGNAL(currentIndexChanged(int)), SLOT(changed()));
41 QListWidgetItem *item = new QListWidgetItem(i18n("DVD"), deinterlaceMediaList);
42 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
43 item->setCheckState(Qt::Checked);
45 item = new QListWidgetItem(i18n("VCD"), deinterlaceMediaList);
46 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
47 item->setCheckState(Qt::Unchecked);
49 item = new QListWidgetItem(i18n("File"), deinterlaceMediaList);
50 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
51 item->setCheckState(Qt::Unchecked);
54 xine_t *xine = xine_new();
55 Q_ASSERT(xine);
56 xine_init(xine);
57 xine_video_port_t *nullVideoPort = xine_open_video_driver(xine, "auto", XINE_VISUAL_TYPE_NONE, 0);
58 xine_post_t *deinterlacer = xine_post_init(xine, "tvtime", 1, 0, &nullVideoPort);
59 if (deinterlacer) {
60 xine_post_in_t *paraInput = xine_post_input(deinterlacer, "parameters");
61 Q_ASSERT(paraInput);
62 Q_ASSERT(paraInput->data);
63 xine_post_api_t *api = reinterpret_cast<xine_post_api_t *>(paraInput->data);
64 xine_post_api_descr_t *desc = api->get_param_descr();
65 for (int i = 0; desc->parameter[i].type != POST_PARAM_TYPE_LAST; ++i) {
66 xine_post_api_parameter_t &p = desc->parameter[i];
67 switch (p.type) {
68 case POST_PARAM_TYPE_INT: /* integer (or vector of integers) */
69 if (0 == strcmp(p.name, "method") && p.enum_values) {
70 for (int j = 0; p.enum_values[j]; ++j) {
71 deinterlaceMethodBox->addItem(p.enum_values[j]);
74 break;
75 case POST_PARAM_TYPE_DOUBLE: /* double (or vector of doubles) */
76 case POST_PARAM_TYPE_CHAR: /* char (or vector of chars = string) */
77 case POST_PARAM_TYPE_STRING: /* (char *), ASCIIZ */
78 case POST_PARAM_TYPE_STRINGLIST: /* (char **) list, NULL terminated */
79 case POST_PARAM_TYPE_BOOL: /* integer (0 or 1) */
80 break;
81 case POST_PARAM_TYPE_LAST: /* terminator of parameter list */
82 default:
83 kFatal() << "invalid type";
87 xine_post_dispose(xine, deinterlacer);
88 } else {
89 m_noDeinterlace = true;
90 deinterlaceGroupBox->setEnabled(false);
92 xine_close_video_driver(xine, nullVideoPort);
93 xine_exit(xine);
95 load();
98 void XineOptions::load()
100 KConfigGroup cg(m_config, "Settings");
101 if (!m_noDeinterlace) {
102 deinterlaceMediaList->item(0)->setCheckState(cg.readEntry("deinterlaceDVD", true) ? Qt::Checked : Qt::Unchecked);
103 deinterlaceMediaList->item(1)->setCheckState(cg.readEntry("deinterlaceVCD", false) ? Qt::Checked : Qt::Unchecked);
104 deinterlaceMediaList->item(2)->setCheckState(cg.readEntry("deinterlaceFile", false) ? Qt::Checked : Qt::Unchecked);
105 deinterlaceMethodBox->setCurrentIndex(cg.readEntry("deinterlaceMethod", 0));
109 void XineOptions::save()
111 KConfigGroup cg(m_config, "Settings");
112 if (!m_noDeinterlace) {
113 cg.writeEntry("deinterlaceDVD", deinterlaceMediaList->item(0)->checkState() == Qt::Checked);
114 cg.writeEntry("deinterlaceVCD", deinterlaceMediaList->item(1)->checkState() == Qt::Checked);
115 cg.writeEntry("deinterlaceFile", deinterlaceMediaList->item(2)->checkState() == Qt::Checked);
116 cg.writeEntry("deinterlaceMethod", deinterlaceMethodBox->currentIndex());
120 void XineOptions::defaults()
122 if (!m_noDeinterlace) {
123 deinterlaceMediaList->item(0)->setCheckState(Qt::Checked);
124 deinterlaceMediaList->item(1)->setCheckState(Qt::Unchecked);
125 deinterlaceMediaList->item(2)->setCheckState(Qt::Unchecked);
126 deinterlaceMethodBox->setCurrentIndex(0);
130 #include "xineoptions.moc"
131 // vim: sw=4 sts=4 et tw=100