00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qfile.h>
00024 #include <qdir.h>
00025 #include <qdialog.h>
00026 #include <qimage.h>
00027 #include <qpixmap.h>
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 #include <qpushbutton.h>
00031 #include <qtoolbutton.h>
00032 #include <qcheckbox.h>
00033 #include <qtooltip.h>
00034 #include <qstyle.h>
00035 #include <qwhatsthis.h>
00036
00037 #include <kapplication.h>
00038 #include <kbuttonbox.h>
00039 #include <kcombobox.h>
00040 #include <kdesktopfile.h>
00041 #include <kdialog.h>
00042 #include <kglobal.h>
00043 #include <klineedit.h>
00044 #include <klocale.h>
00045 #include <kiconloader.h>
00046 #include <kmimemagic.h>
00047 #include <krun.h>
00048 #include <kstandarddirs.h>
00049 #include <kstringhandler.h>
00050 #include <kuserprofile.h>
00051 #include <kurlcompletion.h>
00052 #include <kurlrequester.h>
00053 #include <dcopclient.h>
00054 #include <kmimetype.h>
00055 #include <kservicegroup.h>
00056 #include <klistview.h>
00057 #include <ksycoca.h>
00058
00059 #include "kopenwith.h"
00060 #include "kopenwith_p.h"
00061
00062 #include <kdebug.h>
00063 #include <assert.h>
00064 #include <stdlib.h>
00065
00066 template class QPtrList<QString>;
00067
00068 #define SORT_SPEC (QDir::DirsFirst | QDir::Name | QDir::IgnoreCase)
00069
00070
00071
00072
00073 KAppTreeListItem::KAppTreeListItem( KListView* parent, const QString & name,
00074 const QPixmap& pixmap, bool parse, bool dir, const QString &p, const QString &c )
00075 : QListViewItem( parent, name )
00076 {
00077 init(pixmap, parse, dir, p, c);
00078 }
00079
00080
00081
00082
00083 KAppTreeListItem::KAppTreeListItem( QListViewItem* parent, const QString & name,
00084 const QPixmap& pixmap, bool parse, bool dir, const QString &p, const QString &c )
00085 : QListViewItem( parent, name )
00086 {
00087 init(pixmap, parse, dir, p, c);
00088 }
00089
00090
00091
00092
00093 void KAppTreeListItem::init(const QPixmap& pixmap, bool parse, bool dir, const QString &_path, const QString &_exec)
00094 {
00095 setPixmap(0, pixmap);
00096 parsed = parse;
00097 directory = dir;
00098 path = _path;
00099 exec = _exec;
00100 }
00101
00102
00103
00104
00105
00106 QString KAppTreeListItem::key(int column, bool ) const
00107 {
00108 if (directory)
00109 return QString::fromLatin1(" ") + text(column).upper();
00110 else
00111 return text(column).upper();
00112 }
00113
00114 void KAppTreeListItem::activate()
00115 {
00116 if ( directory )
00117 setOpen(!isOpen());
00118 }
00119
00120 void KAppTreeListItem::setOpen( bool o )
00121 {
00122 if( o && !parsed ) {
00123 ((KApplicationTree *) parent())->addDesktopGroup( path, this );
00124 parsed = true;
00125 }
00126 QListViewItem::setOpen( o );
00127 }
00128
00129 bool KAppTreeListItem::isDirectory()
00130 {
00131 return directory;
00132 }
00133
00134
00135
00136 KApplicationTree::KApplicationTree( QWidget *parent )
00137 : KListView( parent ), currentitem(0)
00138 {
00139 addColumn( i18n("Known Applications") );
00140 setRootIsDecorated( true );
00141
00142 addDesktopGroup( QString::null );
00143
00144 connect( this, SIGNAL( currentChanged(QListViewItem*) ),
00145 SLOT( slotItemHighlighted(QListViewItem*) ) );
00146 connect( this, SIGNAL( selectionChanged(QListViewItem*) ),
00147 SLOT( slotSelectionChanged(QListViewItem*) ) );
00148 }
00149
00150
00151
00152 bool KApplicationTree::isDirSel()
00153 {
00154 if (!currentitem) return false;
00155 return currentitem->isDirectory();
00156 }
00157
00158
00159
00160 static QPixmap appIcon(const QString &iconName)
00161 {
00162 QPixmap normal = KGlobal::iconLoader()->loadIcon(iconName, KIcon::Small, 0, KIcon::DefaultState, 0L, true);
00163
00164 if (normal.width() > 20 || normal.height() > 20)
00165 {
00166 QImage tmp = normal.convertToImage();
00167 tmp = tmp.smoothScale(20, 20);
00168 normal.convertFromImage(tmp);
00169 }
00170 return normal;
00171 }
00172
00173 void KApplicationTree::addDesktopGroup( const QString &relPath, KAppTreeListItem *item)
00174 {
00175 KServiceGroup::Ptr root = KServiceGroup::group(relPath);
00176 if (!root || !root->isValid()) return;
00177
00178 KServiceGroup::List list = root->entries();
00179
00180 KAppTreeListItem * newItem;
00181 for( KServiceGroup::List::ConstIterator it = list.begin();
00182 it != list.end(); it++)
00183 {
00184 QString icon;
00185 QString text;
00186 QString relPath;
00187 QString exec;
00188 bool isDir = false;
00189 KSycocaEntry *p = (*it);
00190 if (p->isType(KST_KService))
00191 {
00192 KService *service = static_cast<KService *>(p);
00193
00194 if (service->noDisplay())
00195 continue;
00196
00197 icon = service->icon();
00198 text = service->name();
00199 exec = service->exec();
00200 }
00201 else if (p->isType(KST_KServiceGroup))
00202 {
00203 KServiceGroup *serviceGroup = static_cast<KServiceGroup *>(p);
00204
00205 if (serviceGroup->noDisplay())
00206 continue;
00207
00208 icon = serviceGroup->icon();
00209 text = serviceGroup->caption();
00210 relPath = serviceGroup->relPath();
00211 isDir = true;
00212 if ( text[0] == '.' )
00213 continue;
00214 }
00215 else
00216 {
00217 kdWarning(250) << "KServiceGroup: Unexpected object in list!" << endl;
00218 continue;
00219 }
00220
00221 QPixmap pixmap = appIcon( icon );
00222
00223 if (item)
00224 newItem = new KAppTreeListItem( item, text, pixmap, false, isDir,
00225 relPath, exec );
00226 else
00227 newItem = new KAppTreeListItem( this, text, pixmap, false, isDir,
00228 relPath, exec );
00229 if (isDir)
00230 newItem->setExpandable( true );
00231 }
00232 }
00233
00234
00235
00236
00237 void KApplicationTree::slotItemHighlighted(QListViewItem* i)
00238 {
00239
00240 if(!i)
00241 return;
00242
00243 KAppTreeListItem *item = (KAppTreeListItem *) i;
00244
00245 currentitem = item;
00246
00247 if( (!item->directory ) && (!item->exec.isEmpty()) )
00248 emit highlighted( item->text(0), item->exec );
00249 }
00250
00251
00252
00253
00254 void KApplicationTree::slotSelectionChanged(QListViewItem* i)
00255 {
00256
00257 if(!i)
00258 return;
00259
00260 KAppTreeListItem *item = (KAppTreeListItem *) i;
00261
00262 currentitem = item;
00263
00264 if( ( !item->directory ) && (!item->exec.isEmpty() ) )
00265 emit selected( item->text(0), item->exec );
00266 }
00267
00268
00269
00270 void KApplicationTree::resizeEvent( QResizeEvent * e)
00271 {
00272 setColumnWidth(0, width()-QApplication::style().pixelMetric(QStyle::PM_ScrollBarExtent)
00273 -2*QApplication::style().pixelMetric(QStyle::PM_DefaultFrameWidth));
00274 KListView::resizeEvent(e);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283 class KOpenWithDlgPrivate
00284 {
00285 public:
00286 KOpenWithDlgPrivate() : saveNewApps(false) { };
00287 QPushButton* ok;
00288 bool saveNewApps;
00289 KService::Ptr curService;
00290 };
00291
00292 KOpenWithDlg::KOpenWithDlg( const KURL::List& _urls, QWidget* parent )
00293 :QDialog( parent, 0L, true )
00294 {
00295 setCaption( i18n( "Open With" ) );
00296 QString text;
00297 if( _urls.count() == 1 )
00298 {
00299 text = i18n("<qt>Select the program that should be used to open <b>%1</b>. "
00300 "If the program is not listed, enter the name or click "
00301 "the browse button.</qt>").arg( _urls.first().fileName() );
00302 }
00303 else
00304
00305 text = i18n( "Choose the name of the program with which to open the selected files." );
00306 setServiceType( _urls );
00307 init( text, QString() );
00308 }
00309
00310 KOpenWithDlg::KOpenWithDlg( const KURL::List& _urls, const QString&_text,
00311 const QString& _value, QWidget *parent)
00312 :QDialog( parent, 0L, true )
00313 {
00314 QString caption = KStringHandler::csqueeze( _urls.first().prettyURL() );
00315 if (_urls.count() > 1)
00316 caption += QString::fromLatin1("...");
00317 setCaption(caption);
00318 setServiceType( _urls );
00319 init( _text, _value );
00320 }
00321
00322 KOpenWithDlg::KOpenWithDlg( const QString &serviceType, const QString& value,
00323 QWidget *parent)
00324 :QDialog( parent, 0L, true )
00325 {
00326 setCaption(i18n("Choose Application for %1").arg(serviceType));
00327 QString text = i18n("<qt>Select the program for the file type: <b>%1</b>. "
00328 "If the program is not listed, enter the name or click "
00329 "the browse button.</qt>").arg(serviceType);
00330 qServiceType = serviceType;
00331 init( text, value );
00332 if (remember)
00333 remember->hide();
00334 }
00335
00336 KOpenWithDlg::KOpenWithDlg( QWidget *parent)
00337 :QDialog( parent, 0L, true )
00338 {
00339 setCaption(i18n("Choose Application"));
00340 QString text = i18n("<qt>Select a program. "
00341 "If the program is not listed, enter the name or click "
00342 "the browse button.</qt>");
00343 qServiceType = QString::null;
00344 init( text, QString::null );
00345 }
00346
00347 void KOpenWithDlg::setServiceType( const KURL::List& _urls )
00348 {
00349 if ( _urls.count() == 1 )
00350 {
00351 qServiceType = KMimeType::findByURL( _urls.first())->name();
00352 if (qServiceType == QString::fromLatin1("application/octet-stream"))
00353 qServiceType = QString::null;
00354 }
00355 else
00356 qServiceType = QString::null;
00357 }
00358
00359 void KOpenWithDlg::init( const QString& _text, const QString& _value )
00360 {
00361 d = new KOpenWithDlgPrivate;
00362 bool bReadOnly = kapp && !kapp->authorize("shell_access");
00363 m_terminaldirty = false;
00364 m_pTree = 0L;
00365 m_pService = 0L;
00366 d->curService = 0L;
00367
00368 QBoxLayout *topLayout = new QVBoxLayout( this, KDialog::marginHint(),
00369 KDialog::spacingHint() );
00370 label = new QLabel( _text, this );
00371 topLayout->addWidget(label);
00372
00373 QHBoxLayout* hbox = new QHBoxLayout(topLayout);
00374
00375 QToolButton *clearButton = new QToolButton( this );
00376 clearButton->setIconSet( BarIcon( "locationbar_erase" ) );
00377 clearButton->setFixedSize( clearButton->sizeHint() );
00378 connect( clearButton, SIGNAL( clicked() ), SLOT( slotClear() ) );
00379 QToolTip::add( clearButton, i18n( "Clear input field" ) );
00380
00381 hbox->addWidget( clearButton );
00382
00383 if (!bReadOnly)
00384 {
00385
00386 KHistoryCombo *combo = new KHistoryCombo();
00387 combo->setDuplicatesEnabled( false );
00388 KConfig *kc = KGlobal::config();
00389 KConfigGroupSaver ks( kc, QString::fromLatin1("Open-with settings") );
00390 int max = kc->readNumEntry( QString::fromLatin1("Maximum history"), 15 );
00391 combo->setMaxCount( max );
00392 int mode = kc->readNumEntry(QString::fromLatin1("CompletionMode"),
00393 KGlobalSettings::completionMode());
00394 combo->setCompletionMode((KGlobalSettings::Completion)mode);
00395 QStringList list = kc->readListEntry( QString::fromLatin1("History") );
00396 combo->setHistoryItems( list, true );
00397 edit = new KURLRequester( combo, this );
00398 }
00399 else
00400 {
00401 clearButton->hide();
00402 edit = new KURLRequester( this );
00403 edit->lineEdit()->setReadOnly(true);
00404 edit->button()->hide();
00405 }
00406
00407 edit->setURL( _value );
00408 QWhatsThis::add(edit,i18n(
00409 "Following the command, you can have several place holders which will be replaced "
00410 "with the actual values when the actual program is run:\n"
00411 "%f - a single file name\n"
00412 "%F - a list of files; use for applications that can open several local files at once\n"
00413 "%u - a single URL\n"
00414 "%U - a list of URLs\n"
00415 "%d - the directory of the file to open\n"
00416 "%D - a list of directories\n"
00417 "%i - the icon\n"
00418 "%m - the mini-icon\n"
00419 "%c - the comment"));
00420
00421 hbox->addWidget(edit);
00422
00423 if ( edit->comboBox() ) {
00424 KURLCompletion *comp = new KURLCompletion( KURLCompletion::ExeCompletion );
00425 edit->comboBox()->setCompletionObject( comp );
00426 edit->comboBox()->setAutoDeleteCompletionObject( true );
00427 }
00428
00429 connect ( edit, SIGNAL(returnPressed()), SLOT(slotOK()) );
00430 connect ( edit, SIGNAL(textChanged(const QString&)), SLOT(slotTextChanged()) );
00431
00432 m_pTree = new KApplicationTree( this );
00433 topLayout->addWidget(m_pTree);
00434
00435 connect( m_pTree, SIGNAL( selected( const QString&, const QString& ) ),
00436 SLOT( slotSelected( const QString&, const QString& ) ) );
00437 connect( m_pTree, SIGNAL( highlighted( const QString&, const QString& ) ),
00438 SLOT( slotHighlighted( const QString&, const QString& ) ) );
00439 connect( m_pTree, SIGNAL( doubleClicked(QListViewItem*) ),
00440 SLOT( slotDbClick() ) );
00441
00442 terminal = new QCheckBox( i18n("Run in &terminal"), this );
00443 if (bReadOnly)
00444 terminal->hide();
00445 connect(terminal, SIGNAL(toggled(bool)), SLOT(slotTerminalToggled(bool)));
00446
00447 topLayout->addWidget(terminal);
00448
00449 QBoxLayout* nocloseonexitLayout = new QHBoxLayout( 0, 0, KDialog::spacingHint() );
00450 QSpacerItem* spacer = new QSpacerItem( 20, 0, QSizePolicy::Fixed, QSizePolicy::Minimum );
00451 nocloseonexitLayout->addItem( spacer );
00452
00453 nocloseonexit = new QCheckBox( i18n("&Do not close when command exits"), this );
00454 nocloseonexit->setChecked( false );
00455 nocloseonexit->setDisabled( true );
00456
00457
00458
00459 KConfigGroup confGroup( KGlobal::config(), QString::fromLatin1("General") );
00460 QString preferredTerminal = confGroup.readPathEntry(QString::fromLatin1("TerminalApplication"), QString::fromLatin1("konsole"));
00461
00462 if (bReadOnly || preferredTerminal != "konsole")
00463 nocloseonexit->hide();
00464
00465 nocloseonexitLayout->addWidget( nocloseonexit );
00466 topLayout->addLayout( nocloseonexitLayout );
00467
00468 if (!qServiceType.isNull())
00469 {
00470 remember = new QCheckBox(i18n("&Remember application association for this type of file"), this);
00471
00472 topLayout->addWidget(remember);
00473 }
00474 else
00475 remember = 0L;
00476
00477
00478 KButtonBox* b = new KButtonBox( this );
00479 b->addStretch( 2 );
00480
00481 d->ok = b->addButton( i18n ( "&OK" ) );
00482 d->ok->setDefault( true );
00483 connect( d->ok, SIGNAL( clicked() ), SLOT( slotOK() ) );
00484
00485 QPushButton* cancel = b->addButton( i18n( "&Cancel" ) );
00486 connect( cancel, SIGNAL( clicked() ), SLOT( reject() ) );
00487
00488 b->layout();
00489 topLayout->addWidget( b );
00490
00491
00492
00493
00494
00495 edit->setFocus();
00496 slotTextChanged();
00497 }
00498
00499
00500
00501
00502 KOpenWithDlg::~KOpenWithDlg()
00503 {
00504 delete d;
00505 d = 0;
00506 }
00507
00508
00509
00510 void KOpenWithDlg::slotClear()
00511 {
00512 edit->setURL(QString::null);
00513 edit->setFocus();
00514 }
00515
00516
00517
00518
00519 void KOpenWithDlg::slotSelected( const QString& , const QString& _exec )
00520 {
00521 kdDebug(250)<<"KOpenWithDlg::slotSelected"<<endl;
00522 KService::Ptr pService = d->curService;
00523 edit->setURL( _exec );
00524 d->curService = pService;
00525 }
00526
00527
00528
00529
00530 void KOpenWithDlg::slotHighlighted( const QString& _name, const QString& )
00531 {
00532 kdDebug(250)<<"KOpenWithDlg::slotHighlighted"<<endl;
00533 qName = _name;
00534 d->curService = KService::serviceByName( qName );
00535 if (!m_terminaldirty)
00536 {
00537
00538 terminal->setChecked(d->curService->terminal());
00539 QString terminalOptions = d->curService->terminalOptions();
00540 nocloseonexit->setChecked( (terminalOptions.contains( "--noclose" ) > 0) );
00541 m_terminaldirty = false;
00542 }
00543 }
00544
00545
00546
00547 void KOpenWithDlg::slotTextChanged()
00548 {
00549 kdDebug(250)<<"KOpenWithDlg::slotTextChanged"<<endl;
00550
00551 d->curService = 0L;
00552 d->ok->setEnabled( !edit->url().isEmpty());
00553 }
00554
00555
00556
00557 void KOpenWithDlg::slotTerminalToggled(bool)
00558 {
00559
00560 m_terminaldirty = true;
00561 nocloseonexit->setDisabled( ! terminal->isChecked() );
00562 }
00563
00564
00565
00566 void KOpenWithDlg::slotDbClick()
00567 {
00568 if (m_pTree->isDirSel() ) return;
00569 slotOK();
00570 }
00571
00572 void KOpenWithDlg::setSaveNewApplications(bool b)
00573 {
00574 d->saveNewApps = b;
00575 }
00576
00577 void KOpenWithDlg::slotOK()
00578 {
00579 QString fullExec(edit->url());
00580
00581 QString serviceName;
00582 QString initialServiceName;
00583 QString preferredTerminal;
00584 m_pService = d->curService;
00585 if (!m_pService) {
00586
00587
00588
00589 serviceName = KRun::binaryName( fullExec, true );
00590 if (serviceName.isEmpty())
00591 {
00592
00593 return;
00594 }
00595 initialServiceName = serviceName;
00596 kdDebug(250) << "initialServiceName=" << initialServiceName << endl;
00597 int i = 1;
00598 bool ok = false;
00599
00600 do {
00601 kdDebug(250) << "looking for service " << serviceName << endl;
00602 KService::Ptr serv = KService::serviceByDesktopName( serviceName );
00603 ok = !serv;
00604
00605 if ( serv && serv->type() == "Application")
00606 {
00607 QString exec = serv->exec();
00608 exec.replace("%u", "", false);
00609 exec.replace("%f", "", false);
00610 exec.replace("-caption %c", "");
00611 exec.replace("-caption \"%c\"", "");
00612 exec.replace("%i", "");
00613 exec.replace("%m", "");
00614 exec = exec.simplifyWhiteSpace();
00615 if (exec == fullExec)
00616 {
00617 ok = true;
00618 m_pService = serv;
00619 kdDebug(250) << k_funcinfo << "OK, found identical service: " << serv->desktopEntryPath() << endl;
00620 }
00621 }
00622 if (!ok)
00623 {
00624 ++i;
00625 serviceName = initialServiceName + "-" + QString::number(i);
00626 }
00627 }
00628 while (!ok);
00629 }
00630 if ( m_pService )
00631 {
00632
00633 serviceName = m_pService->name();
00634 initialServiceName = serviceName;
00635 }
00636
00637 if (terminal->isChecked())
00638 {
00639 KConfigGroup confGroup( KGlobal::config(), QString::fromLatin1("General") );
00640 preferredTerminal = confGroup.readPathEntry(QString::fromLatin1("TerminalApplication"), QString::fromLatin1("konsole"));
00641 m_command = preferredTerminal;
00642
00643 if (preferredTerminal == "konsole" && nocloseonexit->isChecked())
00644 m_command += QString::fromLatin1(" --noclose");
00645 m_command += QString::fromLatin1(" -e ");
00646 m_command += edit->url();
00647 kdDebug(250) << "Setting m_command to " << m_command << endl;
00648 }
00649 if ( m_pService && terminal->isChecked() != m_pService->terminal() )
00650 m_pService = 0L;
00651
00652 bool bRemember = remember && remember->isChecked();
00653
00654 if ( !bRemember && m_pService)
00655 {
00656 accept();
00657 return;
00658 }
00659
00660 if (!bRemember && !d->saveNewApps)
00661 {
00662
00663 m_pService = new KService(initialServiceName, fullExec, QString::null);
00664 if (terminal->isChecked())
00665 {
00666 m_pService->setTerminal(true);
00667
00668 if (preferredTerminal == "konsole" && nocloseonexit->isChecked())
00669 m_pService->setTerminalOptions("--noclose");
00670 }
00671 accept();
00672 return;
00673 }
00674
00675
00676
00677
00678
00679 QString newPath;
00680 QString oldPath;
00681 QString menuId;
00682 if (m_pService)
00683 {
00684 oldPath = m_pService->desktopEntryPath();
00685 newPath = m_pService->locateLocal();
00686 menuId = m_pService->menuId();
00687 kdDebug(250) << "Updating exitsing service " << m_pService->desktopEntryPath() << " ( " << newPath << " ) " << endl;
00688 }
00689 else
00690 {
00691 newPath = KService::newServicePath(false , serviceName, &menuId);
00692 kdDebug(250) << "Creating new service " << serviceName << " ( " << newPath << " ) " << endl;
00693 }
00694
00695 int maxPreference = 1;
00696 if (!qServiceType.isEmpty())
00697 {
00698 KServiceTypeProfile::OfferList offerList = KServiceTypeProfile::offers( qServiceType );
00699 if (!offerList.isEmpty())
00700 maxPreference = offerList.first().preference();
00701 }
00702
00703 KDesktopFile *desktop = 0;
00704 if (!oldPath.isEmpty() && (oldPath != newPath))
00705 {
00706 KDesktopFile orig(oldPath, true);
00707 desktop = orig.copyTo(newPath);
00708 }
00709 else
00710 {
00711 desktop = new KDesktopFile(newPath);
00712 }
00713 desktop->writeEntry("Type", QString::fromLatin1("Application"));
00714 desktop->writeEntry("Name", initialServiceName);
00715 desktop->writePathEntry("Exec", fullExec);
00716 if (terminal->isChecked())
00717 {
00718 desktop->writeEntry("Terminal", true);
00719
00720 if (preferredTerminal == "konsole" && nocloseonexit->isChecked())
00721 desktop->writeEntry("TerminalOptions", "--noclose");
00722 }
00723 else
00724 {
00725 desktop->writeEntry("Terminal", false);
00726 }
00727 desktop->writeEntry("InitialPreference", maxPreference + 1);
00728
00729
00730 if (bRemember)
00731 {
00732 QStringList mimeList = desktop->readListEntry("MimeType", ';');
00733 if (!qServiceType.isEmpty() && !mimeList.contains(qServiceType))
00734 mimeList.append(qServiceType);
00735 desktop->writeEntry("MimeType", mimeList, ';');
00736
00737 if ( !qServiceType.isEmpty() )
00738 {
00739
00740 KDesktopFile mimeDesktop( locateLocal( "mime", qServiceType + ".desktop" ) );
00741 mimeDesktop.writeEntry( "X-KDE-AutoEmbed", false );
00742 mimeDesktop.sync();
00743 }
00744 }
00745
00746
00747 desktop->sync();
00748 delete desktop;
00749
00750 KService::rebuildKSycoca(this);
00751
00752 m_pService = KService::serviceByMenuId( menuId );
00753
00754 Q_ASSERT( m_pService );
00755
00756 accept();
00757 }
00758
00759 QString KOpenWithDlg::text() const
00760 {
00761 if (!m_command.isEmpty())
00762 return m_command;
00763 else
00764 return edit->url();
00765 }
00766
00767 void KOpenWithDlg::hideNoCloseOnExit()
00768 {
00769
00770 nocloseonexit->setChecked( false );
00771 nocloseonexit->hide();
00772 }
00773
00774 void KOpenWithDlg::hideRunInTerminal()
00775 {
00776 terminal->hide();
00777 hideNoCloseOnExit();
00778 }
00779
00780 void KOpenWithDlg::accept()
00781 {
00782 KHistoryCombo *combo = static_cast<KHistoryCombo*>( edit->comboBox() );
00783 if ( combo ) {
00784 combo->addToHistory( edit->url() );
00785
00786 KConfig *kc = KGlobal::config();
00787 KConfigGroupSaver ks( kc, QString::fromLatin1("Open-with settings") );
00788 kc->writeEntry( QString::fromLatin1("History"), combo->historyItems() );
00789 kc->writeEntry(QString::fromLatin1("CompletionMode"),
00790 combo->completionMode());
00791
00792
00793 kc->sync();
00794 }
00795
00796 QDialog::accept();
00797 }
00798
00799
00801
00802 #ifndef KDE_NO_COMPAT
00803 bool KFileOpenWithHandler::displayOpenWithDialog( const KURL::List& urls )
00804 {
00805 KOpenWithDlg l( urls, i18n("Open with:"), QString::null, 0L );
00806 if ( l.exec() )
00807 {
00808 KService::Ptr service = l.service();
00809 if ( !!service )
00810 return KRun::run( *service, urls );
00811
00812 kdDebug(250) << "No service set, running " << l.text() << endl;
00813 return KRun::run( l.text(), urls );
00814 }
00815 return false;
00816 }
00817 #endif
00818
00819 #include "kopenwith.moc"
00820 #include "kopenwith_p.moc"
00821