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
|
#include <tqcheckbox.h>
#include <tqlayout.h>
#include <tqradiobutton.h>
#include <tqvbuttongroup.h>
#include <tqwhatsthis.h>
#include <tdeapplication.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <kicondialog.h>
#include <klineedit.h>
#include <kinputdialog.h>
#include <tdelocale.h>
#include "kservicelistwidget.h"
#include "filetypedetails.h"
#include "typeslistitem.h"
FileTypeDetails::FileTypeDetails( TQWidget * parent, const char * name )
: TQTabWidget( parent, name ), m_item( 0L )
{
TQString wtstr;
// First tab - General
TQWidget * firstWidget = new TQWidget(this);
TQVBoxLayout *firstLayout = new TQVBoxLayout(firstWidget,KDialog::marginHint(),
KDialog::spacingHint());
TQHBoxLayout *hBox = new TQHBoxLayout(0L, 0, KDialog::spacingHint());
firstLayout->addLayout(hBox, 1);
iconButton = new TDEIconButton(firstWidget);
iconButton->setIconType(TDEIcon::Desktop, TDEIcon::MimeType);
connect(iconButton, TQ_SIGNAL(iconChanged(TQString)), TQ_SLOT(updateIcon(TQString)));
iconButton->setFixedSize(70, 70);
hBox->addWidget(iconButton);
TQWhatsThis::add( iconButton, i18n("This button displays the icon associated"
" with the selected file type. Click on it to choose a different icon.") );
TQGroupBox *gb = new TQGroupBox(i18n("Filename Patterns"), firstWidget);
hBox->addWidget(gb);
TQGridLayout *grid = new TQGridLayout(gb, 3, 2, KDialog::marginHint(),
KDialog::spacingHint());
grid->addRowSpacing(0, fontMetrics().lineSpacing());
extensionLB = new TQListBox(gb);
connect(extensionLB, TQ_SIGNAL(highlighted(int)), TQ_SLOT(enableExtButtons(int)));
grid->addMultiCellWidget(extensionLB, 1, 2, 0, 0);
grid->setRowStretch(0, 0);
grid->setRowStretch(1, 1);
grid->setRowStretch(2, 0);
TQWhatsThis::add( extensionLB, i18n("This box contains a list of patterns that can be"
" used to identify files of the selected type. For example, the pattern *.txt is"
" associated with the file type 'text/plain'; all files ending in '.txt' are recognized"
" as plain text files.") );
addExtButton = new TQPushButton(i18n("Add..."), gb);
addExtButton->setEnabled(false);
connect(addExtButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(addExtension()));
grid->addWidget(addExtButton, 1, 1);
TQWhatsThis::add( addExtButton, i18n("Add a new pattern for the selected file type.") );
removeExtButton = new TQPushButton(i18n("Remove"), gb);
removeExtButton->setEnabled(false);
connect(removeExtButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(removeExtension()));
grid->addWidget(removeExtButton, 2, 1);
TQWhatsThis::add( removeExtButton, i18n("Remove the selected filename pattern.") );
gb = new TQGroupBox(i18n("Description"), firstWidget);
firstLayout->addWidget(gb);
gb->setColumnLayout(1, TQt::Horizontal);
description = new KLineEdit(gb);
connect(description, TQ_SIGNAL(textChanged(const TQString &)),
TQ_SLOT(updateDescription(const TQString &)));
wtstr = i18n("You can enter a short description for files of the selected"
" file type (e.g. 'HTML Page'). This description will be used by applications"
" like Konqueror to display directory content.");
TQWhatsThis::add( gb, wtstr );
TQWhatsThis::add( description, wtstr );
serviceListWidget = new KServiceListWidget( KServiceListWidget::SERVICELIST_APPLICATIONS, firstWidget );
connect( serviceListWidget, TQ_SIGNAL(changed(bool)), this, TQ_SIGNAL(changed(bool)));
firstLayout->addWidget(serviceListWidget, 5);
// Second tab - Embedding
TQWidget * secondWidget = new TQWidget(this);
TQVBoxLayout *secondLayout = new TQVBoxLayout(secondWidget, KDialog::marginHint(),
KDialog::spacingHint());
m_autoEmbed = new TQVButtonGroup( i18n("Left Click Action"), secondWidget );
m_autoEmbed->layout()->setSpacing( KDialog::spacingHint() );
secondLayout->addWidget( m_autoEmbed, 1 );
m_autoEmbed->setSizePolicy( TQSizePolicy( (TQSizePolicy::SizeType)3, (TQSizePolicy::SizeType)0, m_autoEmbed->sizePolicy().hasHeightForWidth() ) );
// The order of those three items is very important. If you change it, fix typeslistitem.cpp !
new TQRadioButton( i18n("Show file in embedded viewer"), m_autoEmbed );
new TQRadioButton( i18n("Show file in separate viewer"), m_autoEmbed );
m_rbGroupSettings = new TQRadioButton( i18n("Use settings for '%1' group"), m_autoEmbed );
connect(m_autoEmbed, TQ_SIGNAL( clicked( int ) ), TQ_SLOT( slotAutoEmbedClicked( int ) ));
m_chkAskSave = new TQCheckBox( i18n("Ask whether to save to disk instead"), m_autoEmbed);
connect(m_chkAskSave, TQ_SIGNAL( toggled(bool) ), TQ_SLOT( slotAskSaveToggled(bool) ));
TQWhatsThis::add( m_autoEmbed, i18n("Here you can configure what the Konqueror file manager"
" will do when you click on a file of this type. Konqueror can display the file in"
" an embedded viewer or start up a separate application. If set to 'Use settings for G group',"
" Konqueror will behave according to the settings of the group G this type belongs to,"
" for instance 'image' if the current file type is image/png.") );
secondLayout->addSpacing(10);
embedServiceListWidget = new KServiceListWidget( KServiceListWidget::SERVICELIST_SERVICES, secondWidget );
embedServiceListWidget->setMinimumHeight( serviceListWidget->sizeHint().height() );
connect( embedServiceListWidget, TQ_SIGNAL(changed(bool)), this, TQ_SIGNAL(changed(bool)));
secondLayout->addWidget(embedServiceListWidget, 3);
addTab( firstWidget, i18n("&General") );
addTab( secondWidget, i18n("&Embedding") );
}
void FileTypeDetails::updateRemoveButton()
{
removeExtButton->setEnabled(extensionLB->count()>0);
}
void FileTypeDetails::updateIcon(TQString icon)
{
if (!m_item)
return;
m_item->setIcon(icon);
emit changed(true);
}
void FileTypeDetails::updateDescription(const TQString &desc)
{
if (!m_item)
return;
m_item->setComment(desc);
emit changed(true);
}
void FileTypeDetails::addExtension()
{
if ( !m_item )
return;
bool ok;
TQString ext = KInputDialog::getText( i18n( "Add New Extension" ),
i18n( "Extension:" ), "*.", &ok, this );
if (ok) {
extensionLB->insertItem(ext);
TQStringList patt = m_item->patterns();
patt += ext;
m_item->setPatterns(patt);
updateRemoveButton();
emit changed(true);
}
}
void FileTypeDetails::removeExtension()
{
if (extensionLB->currentItem() == -1)
return;
if ( !m_item )
return;
TQStringList patt = m_item->patterns();
patt.remove(extensionLB->text(extensionLB->currentItem()));
m_item->setPatterns(patt);
extensionLB->removeItem(extensionLB->currentItem());
updateRemoveButton();
emit changed(true);
}
void FileTypeDetails::slotAutoEmbedClicked( int button )
{
if ( !m_item || (button > 2))
return;
m_item->setAutoEmbed( button );
updateAskSave();
emit changed(true);
}
void FileTypeDetails::updateAskSave()
{
if ( !m_item )
return;
int button = m_item->autoEmbed();
if (button == 2)
{
bool embedParent = TypesListItem::defaultEmbeddingSetting(m_item->majorType());
emit embedMajor(m_item->majorType(), embedParent);
button = embedParent ? 0 : 1;
}
TQString mimeType = m_item->name();
TQString dontAskAgainName;
if (button == 0) // Embedded
dontAskAgainName = "askEmbedOrSave"+mimeType;
else
dontAskAgainName = "askSave"+mimeType;
TDESharedConfig::Ptr config = TDESharedConfig::openConfig("konquerorrc", false, false);
config->setGroup("Notification Messages");
bool ask = config->readEntry(dontAskAgainName).isEmpty();
m_item->getAskSave(ask);
bool neverAsk = false;
if (button == 0)
{
KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
// Don't ask for:
// - html (even new tabs would ask, due to about:blank!)
// - dirs obviously (though not common over HTTP :),
// - images (reasoning: no need to save, most of the time, because fast to see)
// e.g. postscript is different, because takes longer to read, so
// it's more likely that the user might want to save it.
// - multipart/* ("server push", see tdemultipart)
// - other strange 'internal' mimetypes like print/manager...
if ( mime->is( "text/html" ) ||
mime->is( "text/xml" ) ||
mime->is( "inode/directory" ) ||
mimeType.startsWith( "image" ) ||
mime->is( "multipart/x-mixed-replace" ) ||
mime->is( "multipart/replace" ) ||
mimeType.startsWith( "print" ) )
{
neverAsk = true;
}
}
m_chkAskSave->blockSignals(true);
m_chkAskSave->setChecked(ask && !neverAsk);
m_chkAskSave->setEnabled(!neverAsk);
m_chkAskSave->blockSignals(false);
}
void FileTypeDetails::slotAskSaveToggled(bool askSave)
{
if (!m_item)
return;
m_item->setAskSave(askSave);
emit changed(true);
}
void FileTypeDetails::setTypeItem( TypesListItem * tlitem )
{
m_item = tlitem;
if ( tlitem )
iconButton->setIcon(tlitem->icon());
else
iconButton->resetIcon();
description->setText(tlitem ? tlitem->comment() : TQString::null);
if ( tlitem )
m_rbGroupSettings->setText( i18n("Use settings for '%1' group").arg( tlitem->majorType() ) );
extensionLB->clear();
addExtButton->setEnabled(true);
removeExtButton->setEnabled(false);
serviceListWidget->setTypeItem( tlitem );
embedServiceListWidget->setTypeItem( tlitem );
m_autoEmbed->setButton( tlitem ? tlitem->autoEmbed() : -1 );
m_rbGroupSettings->setEnabled( tlitem->canUseGroupSetting() );
if ( tlitem )
extensionLB->insertStringList(tlitem->patterns());
else
extensionLB->clear();
updateAskSave();
}
void FileTypeDetails::enableExtButtons(int /*index*/)
{
removeExtButton->setEnabled(true);
}
#include "filetypedetails.moc"
|