summaryrefslogtreecommitdiffstats
path: root/konqueror/konq_misc.cc
blob: 49d93408239e9b23a19b110b031679d16009112a (plain)
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
/* 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 <kapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <kurifilter.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kwin.h>
#include <kprotocolinfo.h>
#include <kurldrag.h>
#include <kstartupinfo.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
void KonqMisc::abortFullScreenMode()
{
  TQPtrList<KonqMainWindow> *mainWindows = KonqMainWindow::mainWindowList();
  if ( mainWindows )
  {
    TQPtrListIterator<KonqMainWindow> it( *mainWindows );
    for (; it.current(); ++it )
    {
      if ( it.current()->fullScreenMode() )
      {
	KWin::WindowInfo info = KWin::windowInfo( it.current()->winId(), NET::WMDesktop );
	if ( info.valid() && info.isOnCurrentDesktop() )
          it.current()->showNormal();
      }
    }
  }
}

// #### this can probably be removed
KonqMainWindow * KonqMisc::createSimpleWindow( const KURL & _url, const TQString &frameName )
{
  abortFullScreenMode();

  // If _url is 0L, open $HOME [this doesn't happen anymore]
  KURL url;
  if (_url.isEmpty())
     url.setPath(TQDir::homeDirPath());
  else
     url = _url;

  KonqMainWindow *win = new KonqMainWindow( KURL(), false );
  win->setInitialFrameName( frameName );
  win->openURL( 0L, url );
  win->show();

  return win;
}

KonqMainWindow * KonqMisc::createSimpleWindow( const KURL & url, const KParts::URLArgs &args, bool tempFile )
{
  abortFullScreenMode();

  KonqOpenURLRequest req;
  req.args = args;
  req.tempFile = tempFile;
  KonqMainWindow *win = new KonqMainWindow( KURL(), false );
  win->openURL( 0L, url, TQString::null, req );
  win->show();

  return win;
}

KonqMainWindow * KonqMisc::createNewWindow( const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, TQStringList filesToSelect, bool tempFile, bool openURL )
{
  kdDebug() << "KonqMisc::createNewWindow url=" << url << endl;

  // For HTTP or html files, use the web browsing profile, otherwise use filemanager profile
  TQString profileName = (!(KProtocolInfo::supportsListing(url)) ||
                        KMimeType::findByURL(url)->name() == "text/html")
          ? "webbrowsing" : "filemanagement";

  TQString profile = locate( "data", TQString::tqfromLatin1("konqueror/profiles/") + profileName );
  return createBrowserWindowFromProfile(profile, profileName, 
					url, args, 
					forbidUseHTML, filesToSelect, tempFile, openURL );
}

KonqMainWindow * KonqMisc::createBrowserWindowFromProfile( const TQString &path, const TQString &filename, const KURL &url, const KParts::URLArgs &args, bool forbidUseHTML, const TQStringList& filesToSelect, bool tempFile, bool openURL )
{
  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 );
  }
  else if( KonqMainWindow::isPreloaded() && KonqMainWindow::preloadedWindow() != NULL )
  {
      mainWindow = KonqMainWindow::preloadedWindow();
      KStartupInfo::setWindowStartupId( mainWindow->winId(), kapp->startupId());
      KonqMainWindow::setPreloadedWindow( NULL );
      KonqMainWindow::setPreloadedFlag( false );
      mainWindow->resetWindow();
      mainWindow->reparseConfiguration();
      if( forbidUseHTML )
          mainWindow->setShowHTML( false );
      KonqOpenURLRequest req;
      req.args = args;
      req.filesToSelect = filesToSelect;
      req.tempFile = tempFile;
      mainWindow->viewManager()->loadViewProfile( path, filename, url, req, true );
  }
  else
  {
      KConfig cfg( path, true );
      cfg.setDollarExpansion( true );
      cfg.setGroup( "Profile" );
      TQString xmluiFile=cfg.readEntry("XMLUIFile","konqueror.rc");

      mainWindow = new KonqMainWindow( KURL(), false, 0, xmluiFile );
      if ( forbidUseHTML )
          mainWindow->setShowHTML( false );
      KonqOpenURLRequest req;
      req.args = args;
      req.filesToSelect = filesToSelect;
      req.tempFile = tempFile;
      mainWindow->viewManager()->loadViewProfile( cfg, filename, url, req, false, openURL );
  }
  mainWindow->setInitialFrameName( args.frameName );
  mainWindow->show();
  return mainWindow;
}

KonqMainWindow * KonqMisc::newWindowFromHistory( KonqView* view, int steps )
{
  int oldPos = view->historyPos();
  int newPos = oldPos + steps;

  const HistoryEntry * he = view->historyAt(newPos);  
  if(!he)
      return 0L;

  KonqMainWindow* mainwindow = createNewWindow(he->url, KParts::URLArgs(), 
					       false, TQStringList(), false, /*openURL*/false);
  if(!mainwindow)
      return 0L;
  KonqView* newView = mainwindow->currentView();  
     
  if(!newView)
      return 0L;

  newView->copyHistory(view);
  newView->setHistoryPos(newPos);
  newView->restoreHistory();
  return mainwindow;
}

TQString KonqMisc::konqFilteredURL( TQWidget* parent, const TQString& _url, const TQString& _path )
{
  if ( !_url.startsWith( "about:" ) ) // Don't filter "about:" URLs
  {
    KURIFilterData data = _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() ) );
        return TQString::null;
      }
      else
        return data.uri().url();
    }
  }
  else if ( _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, const TQString& text )
  : TQLabel( text, 0L, "kde toolbar widget" )	// Use this name for it to be styled!
  , m_mw(mw)
{
  setBackgroundMode( Qt::PaletteButton );
  tqsetAlignment( (TQApplication::reverseLayout() ? Qt::AlignRight : Qt::AlignLeft) |
                 Qt::AlignVCenter | Qt::ShowPrefix );
  setAcceptDrops(true);
  adjustSize();
  validDrag = false;
}

void KonqDraggableLabel::mousePressEvent( TQMouseEvent * ev )
{
  validDrag = true;
  startDragPos = ev->pos();
}

void KonqDraggableLabel::mouseMoveEvent( TQMouseEvent * ev )
{
  if ((startDragPos - ev->pos()).manhattanLength() > TQApplication::startDragDistance())
  {
    validDrag = false;
    if ( m_mw->currentView() )
    {
      KURL::List lst;
      lst.append( m_mw->currentView()->url() );
      TQDragObject * drag = new KURLDrag( lst, m_mw );
      drag->setPixmap( KMimeType::pixmapForURL( lst.first(), 0, KIcon::Small ) );
      drag->dragCopy();
    }
  }
}

void KonqDraggableLabel::mouseReleaseEvent( TQMouseEvent * )
{
  validDrag = false;
}

void KonqDraggableLabel::dragEnterEvent( TQDragEnterEvent *ev )
{
  if ( KURLDrag::canDecode( ev ) )
    ev->acceptAction();
}

void KonqDraggableLabel::dropEvent( TQDropEvent* ev )
{
  _savedLst.clear();
  if ( KURLDrag::decode( ev, _savedLst ) ) {
    TQTimer::singleShot(0, this, TQT_SLOT(delayedOpenURL()));
  }
}

void KonqDraggableLabel::delayedOpenURL()
{
    m_mw->openURL( 0L, _savedLst.first() );
}

#include "konq_misc.moc"