19 #include "kmimetypechooser.h"
21 #include <tdeconfig.h>
22 #include <kiconloader.h>
23 #include <tdelistview.h>
24 #include <tdelocale.h>
25 #include <kmimetype.h>
28 #include <tdesycoca.h>
32 #include <tqlineedit.h>
33 #include <tqpushbutton.h>
34 #include <tqwhatsthis.h>
37 class KMimeTypeChooserPrivate
40 TDEListView *lvMimeTypes;
41 TQPushButton *btnEditMimeType;
43 TQString defaultgroup;
51 const TQStringList &selMimeTypes,
52 const TQString &defaultGroup,
53 const TQStringList &groupsToShow,
57 : TQVBox( parent, name )
59 d =
new KMimeTypeChooserPrivate();
61 d->btnEditMimeType = 0;
62 d->defaultgroup = defaultGroup;
63 d->groups = groupsToShow;
66 setSpacing( KDialogBase::spacingHint() );
68 if ( !text.isEmpty() )
70 new TQLabel( text,
this );
73 d->lvMimeTypes =
new TDEListView(
this );
75 d->lvMimeTypes->addColumn( i18n(
"Mime Type") );
80 d->lvMimeTypes->addColumn( i18n(
"Comment") );
81 d->lvMimeTypes->setColumnWidthMode( 1, TQListView::Manual );
84 d->lvMimeTypes->addColumn( i18n(
"Patterns") );
86 d->lvMimeTypes->setRootIsDecorated(
true );
88 loadMimeTypes( selMimeTypes );
92 TQHBox *btns =
new TQHBox(
this );
93 ((TQBoxLayout*)btns->layout())->addStretch(1);
94 d->btnEditMimeType =
new TQPushButton( i18n(
"&Edit..."), btns );
96 connect( d->btnEditMimeType, TQ_SIGNAL(clicked()),
this, TQ_SLOT(
editMimeType()) );
97 d->btnEditMimeType->setEnabled(
false );
98 connect( d->lvMimeTypes, TQ_SIGNAL( doubleClicked ( TQListViewItem * )),
100 connect( d->lvMimeTypes, TQ_SIGNAL(currentChanged(TQListViewItem*)),
101 this, TQ_SLOT(slotCurrentChanged(TQListViewItem*)) );
103 TQWhatsThis::add( d->btnEditMimeType, i18n(
104 "Click this button to display the familiar TDE mime type editor.") );
108 KMimeTypeChooser::~KMimeTypeChooser()
113 void KMimeTypeChooser::loadMimeTypes(
const TQStringList &_selectedMimeTypes )
115 TQStringList selMimeTypes;
117 if ( !_selectedMimeTypes.isEmpty() )
118 selMimeTypes = _selectedMimeTypes;
122 d->lvMimeTypes->clear();
124 TQMap<TQString,TQListViewItem*> groups;
127 TQValueListIterator<KMimeType::Ptr> it(mimetypes.begin());
129 TQListViewItem *groupItem;
130 bool agroupisopen =
false;
131 TQListViewItem *idefault = 0;
132 TQListViewItem *firstChecked = 0;
134 for (; it != mimetypes.end(); ++it)
138 TQString maj =
mimetype.left(index);
140 if ( d->groups.count() && !d->groups.contains( maj ) )
145 TQMapIterator<TQString,TQListViewItem*> mit = groups.find( maj );
146 if ( mit == groups.end() )
148 groupItem =
new TQListViewItem( d->lvMimeTypes, maj );
149 groups.insert( maj, groupItem );
150 if ( maj == d->defaultgroup )
151 idefault = groupItem;
154 groupItem = mit.data();
156 TQCheckListItem *item =
new TQCheckListItem( groupItem, min, TQCheckListItem::CheckBox );
157 item->setPixmap( 0, SmallIcon( (*it)->icon(TQString::null,
false) ) );
163 item->setText( cl, (*it)->comment(TQString::null,
false) );
168 item->setText( cl, (*it)->patterns().join(
"; ") );
170 if ( selMimeTypes.contains(mimetype) )
173 groupItem->setOpen(
true );
181 d->lvMimeTypes->ensureItemVisible( firstChecked );
183 if ( !agroupisopen && idefault )
185 idefault->setOpen(
true );
186 d->lvMimeTypes->ensureItemVisible( idefault );
192 if ( !(d->lvMimeTypes->currentItem() && (d->lvMimeTypes->currentItem())->parent()) )
194 TQString mt = (d->lvMimeTypes->currentItem()->parent())->text( 0 ) +
"/" + (d->lvMimeTypes->currentItem())->text( 0 );
196 connect( KSycoca::self(), TQ_SIGNAL(databaseChanged()),
197 this, TQ_SLOT(slotSycocaDatabaseChanged()) );
198 TQString keditfiletype = TQString::fromLatin1(
"keditfiletype");
200 +
" --parent " + TQString::number( (ulong)topLevelWidget()->winId())
201 +
" " + TDEProcess::quote(mt),
202 keditfiletype, keditfiletype );
205 void KMimeTypeChooser::slotCurrentChanged(TQListViewItem* i)
207 if ( d->btnEditMimeType )
208 d->btnEditMimeType->setEnabled( i->parent() );
211 void KMimeTypeChooser::slotSycocaDatabaseChanged()
213 if ( KSycoca::self()->isChanged(
"mime") )
220 TQListViewItemIterator it( d->lvMimeTypes );
221 for (; it.current(); ++it)
223 if ( it.current()->parent() && ((TQCheckListItem*)it.current())->isOn() )
224 l << it.current()->parent()->text(0) +
"/" + it.current()->text(0);
234 TQListViewItemIterator it( d->lvMimeTypes );
235 for (; it.current(); ++it)
237 if ( it.current()->parent() && ((TQCheckListItem*)it.current())->isOn() )
240 if ( p->name() != defMT )
250 const TQString &caption,
251 const TQString& text,
252 const TQStringList &selMimeTypes,
253 const TQString &defaultGroup,
254 const TQStringList &groupsToShow,
256 TQWidget *parent,
const char *name )
257 : KDialogBase(parent, name, true, caption, Cancel|Ok, Ok)
260 defaultGroup, groupsToShow, visuals,
262 setMainWidget(m_chooser);
264 TDEConfigGroup group( TDEGlobal::config(),
"KMimeTypeChooserDialog");
265 TQSize defaultSize( 400, 300 );
266 resize( group.readSizeEntry(
"size", &defaultSize) );
270 const TQString &caption,
271 const TQString& text,
272 const TQStringList &selMimeTypes,
273 const TQString &defaultGroup,
274 TQWidget *parent,
const char *name )
275 : KDialogBase(parent, name, true, caption, Cancel|Ok, Ok)
278 defaultGroup, TQStringList(),
281 setMainWidget(m_chooser);
283 TDEConfigGroup group( TDEGlobal::config(),
"KMimeTypeChooserDialog");
284 TQSize defaultSize( 400, 300 );
285 resize( group.readSizeEntry(
"size", &defaultSize) );
289 KMimeTypeChooserDialog::~KMimeTypeChooserDialog()
291 TDEConfigGroup group( TDEGlobal::config(),
"KMimeTypeChooserDialog");
292 group.writeEntry(
"size", size());
296 #include "kmimetypechooser.moc"
KMimeTypeChooserDialog(const TQString &caption=TQString::null, const TQString &text=TQString::null, const TQStringList &selectedMimeTypes=TQStringList(), const TQString &defaultGroup=TQString::null, const TQStringList &groupsToShow=TQStringList(), int visuals=KMimeTypeChooser::Comments|KMimeTypeChooser::Patterns|KMimeTypeChooser::EditButton, TQWidget *parent=0, const char *name=0)
Create a KMimeTypeChooser dialog.
This widget provides a checkable list of all available mimetypes, and a list of selected ones,...
KMimeTypeChooser(const TQString &text=TQString::null, const TQStringList &selectedMimeTypes=0, const TQString &defaultGroup=TQString::null, const TQStringList &groupsToShow=TQStringList(), int visuals=Comments|Patterns|EditButton, TQWidget *parent=0, const char *name=0)
Create a new KMimeTypeChooser.
void editMimeType()
edit the current mimetype Uses KRun to start the KDE mimetype editor for editing the currently select...
@ Patterns
Show the Mimetypes Patterns field in a column ("*.html;*.htm").
@ EditButton
Show the "Edit" button, allowing to edit the selected type.
@ Comments
Show the Mimetypes Comment field in a column ("HTML Document").
TQStringList mimeTypes() const
TQStringList patterns() const
static const TQString & defaultMimeType()
Returns the name of the default mimetype.
static List allMimeTypes()
Get all the mimetypes.
static Ptr mimeType(const TQString &_name)
Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-st...
static pid_t runCommand(TQString cmd)
Run the given shell command and notifies kicker of the starting of the application.
TDEIO_EXPORT MimetypeJob * mimetype(const KURL &url, bool showProgressInfo=true)
Find mimetype for one file or directory.