summaryrefslogtreecommitdiffstats
path: root/ksquirrel/ksquirrelpart/sq_codecsettingsskeleton.ui.h
blob: 2c39790ae354957cbdfdfed92488d3b12fcdaa5a (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
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** TQt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/

void SQ_CodecSettingsSkeleton::init()
{
	w = 0;
	sett = 0;
}

void SQ_CodecSettingsSkeleton::addSettingsWidget(const TQString &path)
{
    w = TQWidgetFactory::create(path, 0, this, "skeleton_settings");
    TQWidget *fake;

    if(w)
        fake = TQT_TQWIDGET(w);
    else
	{
		pushApply->setEnabled(false);
		pushOK->setEnabled(false);

		TQTextEdit *t = new TQTextEdit(i18n("Error loading widget from <b>%1</b>. Please check your installation or contact <a href=\"mailto:ksquirrel.iv@gmail.com\">ksquirrel.iv@gmail.com</a>").arg(path), TQString(), groupBox);		
		t->setReadOnly(true);
		fake = t;
	}

    fake->reparent(groupBox, TQPoint(0,0), true);

    TQGridLayout *grid = new TQGridLayout(groupBox, 1, 1, 11, 6);
    grid->addMultiCellWidget(fake, 1, 1, 0, 3);

    TQSpacerItem *spacer = new TQSpacerItem(15, 1, TQSizePolicy::Minimum, TQSizePolicy::Expanding);
    grid->addItem(spacer, 2, 1);
}

void SQ_CodecSettingsSkeleton::recursivelyReadWrite(fmt_settings &settings, bool r)
{
    if(!w)
	return;

    TQObjectList ch = w->childrenListObject();
    fmt_settings::iterator t;

    for(TQObjectList::iterator it = ch.begin();it != ch.end();++it)
    {
	t = settings.find((*it)->name());

	if((*it)->inherits("TQCheckBox"))
	{
	    TQCheckBox *c = dynamic_cast<TQCheckBox *>(*it);

	    if(c && t != settings.end())
	    {
		if(r)
		    c->setChecked((*t).second.bVal);
		else
		    (*t).second.bVal = c->isChecked();
	    }
	}
	else if((*it)->inherits("TQButtonGroup"))
	{
	    TQButtonGroup *c = dynamic_cast<TQButtonGroup *>(*it);

	    if(c && t != settings.end())
	    {
		if(r)
		    c->setButton((*t).second.iVal);
		else
		    (*t).second.iVal = c->selectedId();
	    }
	}
	else if((*it)->inherits("TQSlider"))
	{
	    TQSlider *c = dynamic_cast<TQSlider *>(*it);

	    if(c && t != settings.end())
	    {
		if(r)
		    c->setValue((*t).second.iVal);
		else
		    (*t).second.iVal = c->value();
	    }
	}
	else if((*it)->inherits("KURLRequester"))
	{
	    KURLRequester *u = dynamic_cast<KURLRequester *>(*it);

	    if(u && t != settings.end())
	    {
		if(r)
		    u->setURL((*t).second.sVal);
		else
		{
                    KURL url = u->url(); // get rid of "file://" if present
		    (*t).second.sVal = url.isEmpty() ? "" : url.path().ascii();
		}
	    }
	}
	else if((*it)->inherits("KDoubleSpinBox"))
	{
	    KDoubleSpinBox *d = dynamic_cast<KDoubleSpinBox *>(*it);

	    if(d && t != settings.end())
	    {
		if(r)
		    d->setValue((*t).second.dVal);
		else
		    (*t).second.dVal = d->value();
	    }
	}
	// TQSpinBox should be checked after KDoubleSpinBox !
	else if((*it)->inherits("TQSpinBox"))
	{
	    TQSpinBox *c = dynamic_cast<TQSpinBox *>(*it);

	    if(c && t != settings.end())
	    {
		if(r)
		    c->setValue((*t).second.iVal);
		else
		    (*t).second.iVal = c->value();
	    }
        }
	else if((*it)->inherits("KColorButton"))
	{
	    KColorButton *c = dynamic_cast<KColorButton *>(*it);

	    if(c && t != settings.end())
	    {
		if(r)
		    c->setColor(TQColor(TQString((*t).second.sVal)));
		else
		    (*t).second.sVal = TQString(c->color().name()).ascii();
	    }
	}
    }
}

int SQ_CodecSettingsSkeleton::exec(fmt_settings &settings)
{
    // read settings
    recursivelyReadWrite(settings, true);

    sett = &settings;

    int result = TQDialog::exec();

    // save settings
    if(result == TQDialog::Accepted)
	recursivelyReadWrite(settings, false);

    return result;
}

void SQ_CodecSettingsSkeleton::setCodecInfo( const TQPixmap &pixmap, const TQString &text )
{
	codecIcon->setPixmap(pixmap);
	codecName->setText(text);
}

void SQ_CodecSettingsSkeleton::slotApply()
{
	recursivelyReadWrite(*sett, false);
	emit apply();
}