| /* This file is part of the KDE project |
| Copyright (C) 1998, 1999 David Faure <faure@kde.org> |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; see the file COPYING. If not, write to |
| the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| Boston, MA 02110-1301, USA. |
| */ |
| |
| |
| #include<tqwhatsthis.h> |
| #include<tqstyle.h> |
| #include<tqdir.h> |
| |
| #include<tdeapplication.h> |
| #include<kdebug.h> |
| #include<tdemessagebox.h> |
| #include<kurifilter.h> |
| #include<tdelocale.h> |
| #include<tdestandarddirs.h> |
| #include<twin.h> |
| #include<kprotocolinfo.h> |
| #include<kurldrag.h> |
| #include<tdestartupinfo.h> |
| |
| #include"konq_misc.h" |
| #include"konq_mainwindow.h" |
| #include"konq_viewmgr.h" |
| #include"konq_view.h" |
| |
| /********************************************** |
| * |
| * KonqMisc |
| * |
| **********************************************/ |
| |
| // Terminates fullscreen-mode for any full-screen window on the current desktop |
| voidKonqMisc::abortFullScreenMode() |
| { |
| TQPtrList<KonqMainWindow>*mainWindows=KonqMainWindow::mainWindowList(); |
| if(mainWindows) |
| { |
| TQPtrListIterator<KonqMainWindow>it(*mainWindows); |
| for(;it.current();++it) |
| { |
| if(it.current()->fullScreenMode()) |
| { |
| KWin::WindowInfoinfo=KWin::windowInfo(it.current()->winId(),NET::WMDesktop); |
| if(info.valid()&&info.isOnCurrentDesktop()) |
| it.current()->showNormal(); |
| } |
| } |
| } |
| } |
| |
| // #### this can probably be removed |
| KonqMainWindow*KonqMisc::createSimpleWindow(constKURL&_url,constTQString&frameName) |
| { |
| abortFullScreenMode(); |
| |
| // If _url is 0L, open $HOME [this doesn't happen anymore] |
| KURLurl; |
| if(_url.isEmpty()) |
| url.setPath(TQDir::homeDirPath()); |
| else |
| url=_url; |
| |
| KonqMainWindow*win=newKonqMainWindow(KURL(),false); |
| win->setInitialFrameName(frameName); |
| win->openURL(0L,url); |
| win->show(); |
| |
| returnwin; |
| } |
| |
| KonqMainWindow*KonqMisc::createSimpleWindow(constKURL&url,constKParts::URLArgs&args,booltempFile) |
| { |
| abortFullScreenMode(); |
| |
| KonqOpenURLRequestreq; |
| req.args=args; |
| req.tempFile=tempFile; |
| KonqMainWindow*win=newKonqMainWindow(KURL(),false); |
| win->openURL(0L,url,TQString::null,req); |
| win->show(); |
| |
| returnwin; |
| } |
| |
| KonqMainWindow*KonqMisc::createNewWindow(constKURL&url,constKParts::URLArgs&args,boolforbidUseHTML,TQStringListfilesToSelect,booltempFile,boolopenURL) |
| { |
| kdDebug()<<"KonqMisc::createNewWindow url="<<url<<endl; |
| |
| // For HTTP or html files, use the web browsing profile, otherwise use filemanager profile |
| TQStringprofileName=(!(KProtocolInfo::supportsListing(url))|| |
| KMimeType::findByURL(url)->name()=="text/html") |
| ?"webbrowsing":"filemanagement"; |
| |
| TQStringprofile=locate("data",TQString::fromLatin1("konqueror/profiles/")+profileName); |
| returncreateBrowserWindowFromProfile(profile,profileName, |
| url,args, |
| forbidUseHTML,filesToSelect,tempFile,openURL); |
| } |
| |
| KonqMainWindow*KonqMisc::createBrowserWindowFromProfile(constTQString&path,constTQString&filename,constKURL&url,constKParts::URLArgs&args,boolforbidUseHTML,constTQStringList&filesToSelect,booltempFile,boolopenURL) |
| { |
| kdDebug(1202)<<"void KonqMisc::createBrowserWindowFromProfile()"<<endl; |
| kdDebug(1202)<<"path="<<path<<",filename="<<filename<<",url="<<url.prettyURL()<<endl; |
| abortFullScreenMode(); |
| |
| KonqMainWindow*mainWindow; |
| if(path.isEmpty()) |
| { |
| // The profile doesn't exit -> creating a simple window |
| mainWindow=createSimpleWindow(url,args,tempFile); |
| if(forbidUseHTML) |
| mainWindow->setShowHTML(false); |
| } |
| elseif(KonqMainWindow::isPreloaded()&&KonqMainWindow::preloadedWindow()!=NULL) |
| { |
| mainWindow=KonqMainWindow::preloadedWindow(); |
| TDEStartupInfo::setWindowStartupId(mainWindow->winId(),tdeApp->startupId()); |
| KonqMainWindow::setPreloadedWindow(NULL); |
| KonqMainWindow::setPreloadedFlag(false); |
| mainWindow->resetWindow(); |
| mainWindow->reparseConfiguration(); |
| if(forbidUseHTML) |
| mainWindow->setShowHTML(false); |
| KonqOpenURLRequestreq; |
| req.args=args; |
| req.filesToSelect=filesToSelect; |
| req.tempFile=tempFile; |
| mainWindow->viewManager()->loadViewProfile(path,filename,url,req,true); |
| } |
| else |
| { |
| TDEConfigcfg(path,true); |
| cfg.setDollarExpansion(true); |
| cfg.setGroup("Profile"); |
| TQStringxmluiFile=cfg.readEntry("XMLUIFile","konqueror.rc"); |
| |
| mainWindow=newKonqMainWindow(KURL(),false,0,xmluiFile); |
| if(forbidUseHTML) |
| mainWindow->setShowHTML(false); |
| KonqOpenURLRequestreq; |
| req.args=args; |
| req.filesToSelect=filesToSelect; |
| req.tempFile=tempFile; |
| mainWindow->viewManager()->loadViewProfile(cfg,filename,url,req,false,openURL); |
| } |
| mainWindow->setInitialFrameName(args.frameName); |
| mainWindow->show(); |
| returnmainWindow; |
| } |
| |
| KonqMainWindow*KonqMisc::newWindowFromHistory(KonqView*view,intsteps) |
| { |
| intoldPos=view->historyPos(); |
| intnewPos=oldPos+steps; |
| |
| constHistoryEntry*he=view->historyAt(newPos); |
| if(!he) |
| return0L; |
| |
| KonqMainWindow*mainwindow=createNewWindow(he->url,KParts::URLArgs(), |
| false,TQStringList(),false,/*openURL*/false); |
| if(!mainwindow) |
| return0L; |
| KonqView*newView=mainwindow->currentView(); |
| |
| if(!newView) |
| return0L; |
| |
| newView->copyHistory(view); |
| newView->setHistoryPos(newPos); |
| newView->restoreHistory(); |
| returnmainwindow; |
| } |
| |
| TQStringKonqMisc::konqFilteredURL(TQWidget*parent,constTQString&_url,constTQString&_path) |
| { |
| if(!_url.startsWith("about:"))// Don't filter "about:" URLs |
| { |
| KURIFilterDatadata=_url; |
| |
| if(!_path.isEmpty()) |
| data.setAbsolutePath(_path); |
| |
| // We do not want to the filter to check for executables |
| // from the location bar. |
| data.setCheckForExecutables(false); |
| |
| if(KURIFilter::self()->filterURI(data)) |
| { |
| if(data.uriType()==KURIFilterData::ERROR&&!data.errorMsg().isEmpty()) |
| { |
| KMessageBox::sorry(parent,i18n(data.errorMsg().utf8())); |
| returnTQString::null; |
| } |
| else |
| returndata.uri().url(); |
| } |
| } |
| elseif(_url.startsWith("about:")&&_url!="about:blank"){ |
| // We can't use "about:" as it is, KURL doesn't parse it. |
| if(_url=="about:plugins") |
| return"about:plugins"; |
| return"about:konqueror"; |
| } |
| return_url;// return the original url if it cannot be filtered. |
| } |
| |
| KonqDraggableLabel::KonqDraggableLabel(KonqMainWindow*mw,constTQString&text) |
| :TQLabel(text,0L,"tde toolbar widget")// Use this name for it to be styled! |
| ,m_mw(mw) |
| { |
| setBackgroundMode(TQt::PaletteButton); |
| setAlignment((TQApplication::reverseLayout()?TQt::AlignRight:TQt::AlignLeft)| |
| TQt::AlignVCenter|TQt::ShowPrefix); |
| setAcceptDrops(true); |
| adjustSize(); |
| validDrag=false; |
| } |
| |
| voidKonqDraggableLabel::mousePressEvent(TQMouseEvent*ev) |
| { |
| validDrag=true; |
| startDragPos=ev->pos(); |
| } |
| |
| voidKonqDraggableLabel::mouseMoveEvent(TQMouseEvent*ev) |
| { |
| if((startDragPos-ev->pos()).manhattanLength()>TQApplication::startDragDistance()) |
| { |
| validDrag=false; |
| if(m_mw->currentView()) |
| { |
| KURL::Listlst; |
| lst.append(m_mw->currentView()->url()); |
| TQDragObject*drag=newKURLDrag(lst,m_mw); |
| drag->setPixmap(KMimeType::pixmapForURL(lst.first(),0,TDEIcon::Small)); |
| drag->dragCopy(); |
| } |
| } |
| } |
| |
| voidKonqDraggableLabel::mouseReleaseEvent(TQMouseEvent*) |
| { |
| validDrag=false; |
| } |
| |
| voidKonqDraggableLabel::dragEnterEvent(TQDragEnterEvent*ev) |
| { |
| if(KURLDrag::canDecode(ev)) |
| ev->acceptAction(); |
| } |
| |
| voidKonqDraggableLabel::dropEvent(TQDropEvent*ev) |
| { |
| _savedLst.clear(); |
| if(KURLDrag::decode(ev,_savedLst)){ |
| TQTimer::singleShot(0,this,TQ_SLOT(delayedOpenURL())); |
| } |
| } |
| |
| voidKonqDraggableLabel::delayedOpenURL() |
| { |
| m_mw->openURL(0L,_savedLst.first()); |
| } |
| |
| #include"konq_misc.moc" |