DirFilterPlugin::DirFilterPlugin (QObject* parent, const QVariantList &) :KParts::Plugin (parent) { m_part = qobject_cast<KParts::ReadOnlyPart*>(parent); if (m_part) { connect(m_part, SIGNAL(aboutToOpenURL()), this, SLOT(slotOpenURL())); connect(m_part, SIGNAL(completed()), this, SLOT(slotOpenURLCompleted())); connect(m_part, SIGNAL(completed(bool)), this, SLOT(slotOpenURLCompleted())); } KParts::ListingNotificationExtension* notifyExt = KParts::ListingNotificationExtension::childObject(m_part); if (notifyExt && notifyExt->supportedNotificationEventTypes() != KParts::ListingNotificationExtension::None) { m_listingExt = KParts::ListingFilterExtension::childObject(m_part); connect(notifyExt, SIGNAL(listingEvent(KParts::ListingNotificationExtension::NotificationEventType,KFileItemList)), this, SLOT(slotListingEvent(KParts::ListingNotificationExtension::NotificationEventType,KFileItemList))); m_pFilterMenu = new KActionMenu (KIcon("view-filter"), i18n("View F&ilter"), actionCollection()); actionCollection()->addAction("filterdir", m_pFilterMenu); m_pFilterMenu->setDelayed(false); m_pFilterMenu->setDisabled(true); m_pFilterMenu->setWhatsThis(i18n("Allow to filter the currently displayed items by filetype.")); connect(m_pFilterMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(slotShowPopup())); connect(m_pFilterMenu->menu(), SIGNAL(triggered(QAction*)), this, SLOT(slotItemSelected(QAction*))); }
int main(int argc, char *argv[]) { KCmdLineOptions options; options.add("+file", ki18n("URL to open")); KCmdLineArgs::init(argc, argv, "testkhtml", 0, ki18n("Testkhtml"), "1.0", ki18n("a basic web browser using the KHTML library")); KCmdLineArgs::addCmdLineOptions(options); KApplication a; KCmdLineArgs *args = KCmdLineArgs::parsedArgs( ); if ( args->count() == 0 ) { KCmdLineArgs::usage(); ::exit( 1 ); } new KHTMLGlobal; KXmlGuiWindow *toplevel = new KXmlGuiWindow(); KHTMLPart *doc = new KHTMLPart( toplevel, toplevel, KHTMLPart::BrowserViewGUI ); Dummy *dummy = new Dummy( doc ); QObject::connect( doc->browserExtension(), SIGNAL(openUrlRequest(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), dummy, SLOT(slotOpenURL(KUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)) ); QObject::connect( doc, SIGNAL(completed()), dummy, SLOT(handleDone()) ); if (args->url(0).url().right(4).toLower() == ".xml") { KParts::OpenUrlArguments args(doc->arguments()); args.setMimeType("text/xml"); doc->setArguments(args); } doc->openUrl( args->url(0) ); toplevel->setCentralWidget( doc->widget() ); toplevel->resize( 800, 600); QDomDocument d = doc->domDocument(); QDomElement viewMenu = d.documentElement().firstChild().childNodes().item( 2 ).toElement(); QDomElement e = d.createElement( "action" ); e.setAttribute( "name", "debugRenderTree" ); viewMenu.appendChild( e ); e = d.createElement( "action" ); e.setAttribute( "name", "debugDOMTree" ); viewMenu.appendChild( e ); e = d.createElement( "action" ); e.setAttribute( "name", "debugDoBenchmark" ); viewMenu.appendChild( e ); QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement(); e = d.createElement( "action" ); e.setAttribute( "name", "editable" ); toolBar.insertBefore( e, toolBar.firstChild() ); e = d.createElement( "action" ); e.setAttribute( "name", "navigable" ); toolBar.insertBefore( e, toolBar.firstChild() ); e = d.createElement( "action" ); e.setAttribute( "name", "reload" ); toolBar.insertBefore( e, toolBar.firstChild() ); e = d.createElement( "action" ); e.setAttribute( "name", "print" ); toolBar.insertBefore( e, toolBar.firstChild() ); KAction *action = new KAction(KIcon("view-refresh"), "Reload", doc ); doc->actionCollection()->addAction( "reload", action ); QObject::connect(action, SIGNAL(triggered(bool)), dummy, SLOT(reload())); action->setShortcut(Qt::Key_F5); KAction *bench = new KAction( KIcon(), "Benchmark...", doc ); doc->actionCollection()->addAction( "debugDoBenchmark", bench ); QObject::connect(bench, SIGNAL(triggered(bool)), dummy, SLOT(doBenchmark())); KAction *kprint = new KAction(KIcon("document-print"), "Print", doc ); doc->actionCollection()->addAction( "print", kprint ); QObject::connect(kprint, SIGNAL(triggered(bool)), doc->browserExtension(), SLOT(print())); kprint->setEnabled(true); KToggleAction *ta = new KToggleAction( KIcon("edit-rename"), "Navigable", doc ); doc->actionCollection()->addAction( "navigable", ta ); ta->setShortcuts( KShortcut() ); ta->setChecked(doc->isCaretMode()); QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleNavigable(bool))); ta = new KToggleAction( KIcon("document-properties"), "Editable", doc ); doc->actionCollection()->addAction( "editable", ta ); ta->setShortcuts( KShortcut() ); ta->setChecked(doc->isEditable()); QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleEditable(bool))); toplevel->guiFactory()->addClient( doc ); doc->setJScriptEnabled(true); doc->setJavaEnabled(true); doc->setPluginsEnabled( true ); doc->setURLCursor(QCursor(Qt::PointingHandCursor)); a.setTopWidget(doc->widget()); QWidget::connect(doc, SIGNAL(setWindowCaption(QString)), doc->widget()->topLevelWidget(), SLOT(setCaption(QString))); doc->widget()->show(); toplevel->show(); doc->view()->viewport()->show(); doc->view()->widget()->show(); int ret = a.exec(); return ret; }
// TODO convert to use xmlui file void KuickShow::initGUI( const KURL& startDir ) { KURL startURL( startDir ); if ( !KProtocolInfo::supportsListing( startURL ) ) startURL = KURL(); fileWidget = new FileWidget( startURL, this, "MainWidget" ); setFocusProxy( fileWidget ); KActionCollection *coll = fileWidget->actionCollection(); redirectDeleteAndTrashActions(coll); connect( fileWidget, SIGNAL( fileSelected( const KFileItem * ) ), this, SLOT( slotSelected( const KFileItem * ) )); connect( fileWidget, SIGNAL( fileHighlighted( const KFileItem * )), this, SLOT( slotHighlighted( const KFileItem * ) )); connect( fileWidget, SIGNAL( urlEntered( const KURL& )), this, SLOT( dirSelected( const KURL& )) ); fileWidget->setAcceptDrops(true); connect( fileWidget, SIGNAL( dropped( const KFileItem *, QDropEvent *, const KURL::List & )), this, SLOT( slotDropped( const KFileItem *, QDropEvent *, const KURL::List &)) ); // setup actions KAction *open = KStdAction::open( this, SLOT( slotOpenURL() ), coll, "openURL" ); KAction *print = KStdAction::print( this, SLOT( slotPrint() ), coll, "kuick_print" ); print->setText( i18n("Print Image...") ); KAction *configure = new KAction( i18n("Configure %1...").arg( KGlobal::instance()->aboutData()->programName() ), "configure", KShortcut(), this, SLOT( configuration() ), coll, "kuick_configure" ); KAction *slide = new KAction( i18n("Start Slideshow" ), "ksslide", KShortcut( Key_F2 ), this, SLOT( startSlideShow() ), coll, "kuick_slideshow" ); KAction *about = new KAction( i18n( "About KuickShow" ), "about", KShortcut(), this, SLOT( about() ), coll, "about" ); oneWindowAction = new KToggleAction( i18n("Open Only One Image Window"), "window_new", KShortcut( CTRL+Key_N ), coll, "kuick_one window" ); m_toggleBrowserAction = new KToggleAction( i18n("Show File Browser"), KShortcut( Key_Space ), coll, "toggleBrowser" ); m_toggleBrowserAction->setCheckedState(i18n("Hide File Browser")); connect( m_toggleBrowserAction, SIGNAL( toggled( bool ) ), SLOT( toggleBrowser() )); KAction *showInOther = new KAction( i18n("Show Image"), KShortcut(), this, SLOT( slotShowInOtherWindow() ), coll, "kuick_showInOtherWindow" ); KAction *showInSame = new KAction( i18n("Show Image in Active Window"), KShortcut(), this, SLOT( slotShowInSameWindow() ), coll, "kuick_showInSameWindow" ); KAction *showFullscreen = new KAction( i18n("Show Image in Fullscreen Mode"), KShortcut(), this, SLOT( slotShowFullscreen() ), coll, "kuick_showFullscreen" ); KAction *quit = KStdAction::quit( this, SLOT(slotQuit()), coll, "quit"); // remove QString::null parameter -- ellis coll->readShortcutSettings( QString::null ); m_accel = coll->accel(); // menubar KMenuBar *mBar = menuBar(); QPopupMenu *fileMenu = new QPopupMenu( mBar, "file" ); open->plug( fileMenu ); showInOther->plug( fileMenu ); showInSame->plug( fileMenu ); showFullscreen->plug( fileMenu ); fileMenu->insertSeparator(); slide->plug( fileMenu ); print->plug( fileMenu ); fileMenu->insertSeparator(); quit->plug( fileMenu ); QPopupMenu *editMenu = new QPopupMenu( mBar, "edit" ); coll->action("mkdir")->plug( editMenu ); coll->action("delete")->plug( editMenu ); editMenu->insertSeparator(); coll->action("properties")->plug( editMenu ); // remove the Sorting submenu (and the separator below) // from the main contextmenu KActionMenu *sortingMenu = static_cast<KActionMenu*>( coll->action("sorting menu")); KActionMenu *mainActionMenu = static_cast<KActionMenu*>( coll->action("popupMenu")); QPopupMenu *mainPopup = mainActionMenu->popupMenu(); int sortingIndex = mainPopup->indexOf( sortingMenu->itemId( 0 ) ); int separatorId = mainPopup->idAt( sortingIndex + 1 ); QMenuItem *separatorItem = mainPopup->findItem( separatorId ); if ( separatorItem && separatorItem->isSeparator() ) mainPopup->removeItem( separatorId ); mainActionMenu->remove( sortingMenu ); // add the sorting menu and a separator into the View menu KActionMenu *viewActionMenu = static_cast<KActionMenu*>( coll->action("view menu")); viewActionMenu->popupMenu()->insertSeparator( 0 ); sortingMenu->plug( viewActionMenu->popupMenu(), 0 ); // on top of the menu QPopupMenu *settingsMenu = new QPopupMenu( mBar, "settings" ); configure->plug( settingsMenu ); mBar->insertItem( i18n("&File"), fileMenu ); mBar->insertItem( i18n("&Edit"), editMenu ); viewActionMenu->plug( mBar ); mBar->insertItem( i18n("&Settings"), settingsMenu ); // toolbar KToolBar *tBar = toolBar(); tBar->setText( i18n( "Main Toolbar" ) ); coll->action("up")->plug( tBar ); coll->action("back")->plug( tBar ); coll->action("forward")->plug( tBar ); coll->action("home")->plug( tBar ); coll->action("reload")->plug( tBar ); tBar->insertSeparator(); coll->action( "short view" )->plug( tBar ); coll->action( "detailed view" )->plug( tBar ); coll->action( "preview")->plug( tBar ); tBar->insertSeparator(); configure->plug( tBar ); slide->plug( tBar ); tBar->insertSeparator(); oneWindowAction->plug( tBar ); print->plug( tBar ); tBar->insertSeparator(); about->plug( tBar ); QPopupMenu *help = helpMenu( QString::null, false ); mBar->insertItem( KStdGuiItem::help().text() , help ); KStatusBar* sBar = statusBar(); sBar->insertItem( " ", URL_ITEM, 10 ); sBar->insertItem( " ", META_ITEM, 2 ); sBar->setItemAlignment(URL_ITEM, QLabel::AlignVCenter | QLabel::AlignLeft); fileWidget->setFocus(); KConfig *kc = KGlobal::config(); kc->setGroup("SessionSettings"); bool oneWindow = kc->readBoolEntry("OpenImagesInActiveWindow", true ); oneWindowAction->setChecked( oneWindow ); tBar->show(); // Address box in address tool bar KToolBar *addressToolBar = toolBar( "address_bar" ); const int ID_ADDRESSBAR = 1; cmbPath = new KURLComboBox( KURLComboBox::Directories, true, addressToolBar, "address_combo_box" ); KURLCompletion *cmpl = new KURLCompletion( KURLCompletion::DirCompletion ); cmbPath->setCompletionObject( cmpl ); cmbPath->setAutoDeleteCompletionObject( true ); addressToolBar->insertWidget( ID_ADDRESSBAR, 1, cmbPath); addressToolBar->setItemAutoSized( ID_ADDRESSBAR ); connect( cmbPath, SIGNAL( urlActivated( const KURL& )), this, SLOT( slotSetURL( const KURL& ))); connect( cmbPath, SIGNAL( returnPressed()), this, SLOT( slotURLComboReturnPressed())); fileWidget->initActions(); fileWidget->clearHistory(); dirSelected( fileWidget->url() ); setCentralWidget( fileWidget ); setupGUI( KMainWindow::Save ); coll->action( "reload" )->setShortcut( KStdAccel::reload() ); coll->action( "short view" )->setShortcut(Key_F6); coll->action( "detailed view" )->setShortcut(Key_F7); coll->action( "show hidden" )->setShortcut(Key_F8); coll->action( "mkdir" )->setShortcut(Key_F10); coll->action( "preview" )->setShortcut(Key_F11); coll->action( "separate dirs" )->setShortcut(Key_F12); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); if (a.arguments().count() <= 1) { qWarning() << "Argument expected: url to open"; return 1; } new KHTMLGlobal; KXmlGuiWindow *toplevel = new KXmlGuiWindow(); KHTMLPart *doc = new KHTMLPart(toplevel, toplevel, KHTMLPart::BrowserViewGUI); Dummy *dummy = new Dummy(doc); QObject::connect(doc->browserExtension(), SIGNAL(openUrlRequest(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments)), dummy, SLOT(slotOpenURL(QUrl,KParts::OpenUrlArguments,KParts::BrowserArguments))); QObject::connect(doc, SIGNAL(completed()), dummy, SLOT(handleDone())); QUrl url = QUrl::fromUserInput(a.arguments().at(1)); // TODO support for relative paths if (url.path().right(4).toLower() == ".xml") { KParts::OpenUrlArguments args(doc->arguments()); args.setMimeType("text/xml"); doc->setArguments(args); } doc->openUrl(url); toplevel->setCentralWidget(doc->widget()); toplevel->resize(800, 600); QDomDocument d = doc->domDocument(); QDomElement viewMenu = d.documentElement().firstChild().childNodes().item(2).toElement(); QDomElement e = d.createElement("action"); e.setAttribute("name", "debugRenderTree"); viewMenu.appendChild(e); e = d.createElement("action"); e.setAttribute("name", "debugDOMTree"); viewMenu.appendChild(e); e = d.createElement("action"); e.setAttribute("name", "debugDoBenchmark"); viewMenu.appendChild(e); QDomElement toolBar = d.documentElement().firstChild().nextSibling().toElement(); e = d.createElement("action"); e.setAttribute("name", "editable"); toolBar.insertBefore(e, toolBar.firstChild()); e = d.createElement("action"); e.setAttribute("name", "navigable"); toolBar.insertBefore(e, toolBar.firstChild()); e = d.createElement("action"); e.setAttribute("name", "reload"); toolBar.insertBefore(e, toolBar.firstChild()); e = d.createElement("action"); e.setAttribute("name", "print"); toolBar.insertBefore(e, toolBar.firstChild()); QAction *action = new QAction(QIcon::fromTheme("view-refresh"), "Reload", doc); doc->actionCollection()->addAction("reload", action); QObject::connect(action, SIGNAL(triggered(bool)), dummy, SLOT(reload())); doc->actionCollection()->setDefaultShortcut(action, Qt::Key_F5); QAction *bench = new QAction(QIcon(), "Benchmark...", doc); doc->actionCollection()->addAction("debugDoBenchmark", bench); QObject::connect(bench, SIGNAL(triggered(bool)), dummy, SLOT(doBenchmark())); QAction *kprint = new QAction(QIcon::fromTheme("document-print"), "Print", doc); doc->actionCollection()->addAction("print", kprint); QObject::connect(kprint, SIGNAL(triggered(bool)), doc->browserExtension(), SLOT(print())); kprint->setEnabled(true); KToggleAction *ta = new KToggleAction(QIcon::fromTheme("edit-rename"), "Navigable", doc); doc->actionCollection()->addAction("navigable", ta); ta->setShortcuts(QList<QKeySequence>()); ta->setChecked(doc->isCaretMode()); QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleNavigable(bool))); ta = new KToggleAction(QIcon::fromTheme("document-properties"), "Editable", doc); doc->actionCollection()->addAction("editable", ta); ta->setShortcuts(QList<QKeySequence>()); ta->setChecked(doc->isEditable()); QWidget::connect(ta, SIGNAL(toggled(bool)), dummy, SLOT(toggleEditable(bool))); toplevel->guiFactory()->addClient(doc); doc->setJScriptEnabled(true); doc->setJavaEnabled(true); doc->setPluginsEnabled(true); doc->setURLCursor(QCursor(Qt::PointingHandCursor)); a.setActiveWindow(doc->widget()); QWidget::connect(doc, SIGNAL(setWindowCaption(QString)), doc->widget()->topLevelWidget(), SLOT(setCaption(QString))); doc->widget()->show(); toplevel->show(); doc->view()->viewport()->show(); doc->view()->widget()->show(); int ret = a.exec(); return ret; }