[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Re: [PATCH] New feature: closed tabs trash bin as in Opera
From:       Eduardo Robles Elvira <edulix () gmail ! com>
Date:       2007-04-03 21:37:00
Message-ID: 200704032337.00387.edulix () gmail ! com
[Download RAW message or body]

Hello people, Edulix is back!

I've been working on this thing. There were two points remaining to fix of 
those that David Faure pointed out, and now those have been fixed:

 * one was to use KConfigGroup instead of KConfig. That was easy.
 * the other was to fix the misuse of the m_lock in the undo manager. Now as 
David suggested me today in IRC, I've changed the m_lock and instead of being 
a bool it's an enum with two states: {Enabled, OnlyUndoClosedTabs} so that 
the code is clearer to understand.

The patch works fine here and I belive that konqueror users will like it. I 
haven't got much more to add, but I will answer your questions as needed.

Thanks for your time,
         Eduardo Robles Elvira.

["parche.konqueror" (text/x-diff)]

Index: konqueror/konq_mainwindow.h
===================================================================
--- konqueror/konq_mainwindow.h	(revisión: 647756)
+++ konqueror/konq_mainwindow.h	(copia de trabajo)
@@ -2,6 +2,8 @@
    This file is part of the KDE project
    Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
    Copyright (C) 2000-2004 David Faure <faure@kde.org>
+   Copyright (C) 2006 Eduardo Robles Elvira <edulix@gmail.com>
+   Copyright (C) 2006 Daniel García Moreno <danigm@gmail.com>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
@@ -34,6 +36,7 @@
 #include <QEvent>
 #include <QLabel>
 #include <QCustomEvent>
+#include <QHash>
 
 #include <kfileitem.h>
 #include <klocale.h>
@@ -85,6 +88,8 @@
 class KonqRun;
 class KUrlRequester;
 class KZip;
+class KTemporaryFile;
+class KConfigGroup;
 struct HistoryEntry;
 
 namespace KParts {
@@ -96,6 +101,21 @@
 
 class KonqExtendedBookmarkOwner;
 
+class ClosedTabItem {
+  public:
+    ClosedTabItem(QString url, KonqFrameTabs* tabContainer, QString title, int pos);
+    ~ClosedTabItem();
+    static void setConfig(KConfig *config) { ClosedTabItem::config = config; }
+    QString getGroup() const { return "Closed_Tab"  + QString::number(qHash(this)); \
} +    
+    QString url;
+    KonqFrameTabs* tabContainer;
+    QString title;
+    int pos;
+    KConfigGroup configGroup;
+    static KConfig* config;
+};
+
 class KonqMainWindow : public KParts::MainWindow, public KonqFrameContainerBase
 {
   Q_OBJECT
@@ -386,6 +406,9 @@
   void slotForward(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
   void slotHome();
   void slotHome(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
+  void slotOpenLastClosedTab(ClosedTabItem* closedTabItem = 0L);
+  void slotClosedTabsDisable();
+  void slotAddClosedUrl(KonqFrameBase *tab, KonqFrameTabs* tabContainer);
   void slotGoSystem();
   void slotGoApplications();
   void slotGoMedia();
@@ -480,10 +503,12 @@
   void slotUpAboutToShow();
   void slotBackAboutToShow();
   void slotForwardAboutToShow();
+  void slotClosedTabsListAboutToShow();
 
   void slotUpActivated( int id );
   void slotBackActivated( int id );
   void slotForwardActivated( int id );
+  void slotClosedTabsActivated( int id );
   void slotGoHistoryDelayed();
 
   void slotCompletionModeChanged( KGlobalSettings::Completion );
@@ -620,6 +645,7 @@
   KToolBarPopupAction *m_paUp;
   KToolBarPopupAction *m_paBack;
   KToolBarPopupAction *m_paForward;
+  KToolBarPopupAction *m_paClosedTabs;  /// Action for the trash that contains \
closed tabs  QAction *m_paHome;
 
   KonqBidiHistoryAction *m_paHistory;
@@ -696,6 +722,7 @@
   MapViews m_mapViews;
 
   QPointer<KonqView> m_currentView;
+  QList<ClosedTabItem*> m_closedTabsList;
 
   KBookmarkMenu* m_pBookmarkMenu;
   KonqExtendedBookmarkOwner *m_pBookmarksOwner;
Index: konqueror/konq_mainwindow.cc
===================================================================
--- konqueror/konq_mainwindow.cc	(revisión: 647756)
+++ konqueror/konq_mainwindow.cc	(copia de trabajo)
@@ -2,6 +2,8 @@
    Copyright (C) 1998, 1999 Simon Hausmann <hausmann@kde.org>
    Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
    Copyright (C) 2000-2005 David Faure <faure@kde.org>
+   Copyright (C) 2006 Eduardo Robles Elvira <edulix@gmail.com>
+   Copyright (C) 2006 Daniel García Moreno <danigm@gmail.com>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
@@ -97,11 +99,13 @@
 #include <konq_popupmenu.h>
 #include <konq_settings.h>
 #include <konq_undo.h>
+#include <konq_undo_p.h>
 #include <kprotocolinfo.h>
 #include <kprotocolmanager.h>
 #include <kstandardshortcut.h>
 #include <kstandardaction.h>
 #include <kstandarddirs.h>
+#include <kstringhandler.h>
 #include <ksycoca.h>
 #include <ktemporaryfile.h>
 #include <ktoolbarpopupaction.h>
@@ -146,6 +150,7 @@
 
 QList<KonqMainWindow*> *KonqMainWindow::s_lstViews = 0;
 KConfig * KonqMainWindow::s_comboConfig = 0;
+KConfig * ClosedTabItem::config = 0;
 KCompletion * KonqMainWindow::s_pCompletion = 0;
 QFile * KonqMainWindow::s_crashlog_file = 0;
 bool KonqMainWindow::s_preloaded = false;
@@ -157,6 +162,7 @@
 KonqOpenURLRequest KonqOpenURLRequest::null;
 static KStaticDeleter<KonqHistoryManager> konqHistoryManagerSd;
 static KonqHistoryManager* s_konqHistoryManager;
+unsigned short int m_closedTabsListLength = 10;
 
 static int current_memory_usage( int* limit = NULL );
 
@@ -165,6 +171,26 @@
    m_pKonqMainWindow = w;
 }
 
+
+ClosedTabItem::ClosedTabItem(QString url, KonqFrameTabs* tabContainer, QString \
title, int pos) +      :  url(url), tabContainer(tabContainer), title(title), \
pos(pos), configGroup(config, getGroup()) +{
+  KonqCommand closedTabCommand;
+  closedTabCommand.m_type = KonqUndoManager::CLOSEDTAB;
+  closedTabCommand.m_closedTabItem = this;
+  closedTabCommand.m_valid = true;
+  
+  KonqUndoManager::self()->pushCommand( closedTabCommand );
+  kDebug(1202) << "<<<<<<<<    ClosedTabItem::ClosedTabItem("<< this << ") : " << \
getGroup() << endl; +}
+
+
+ClosedTabItem::~ClosedTabItem()
+{
+   config->deleteGroup( getGroup() );
+   kDebug(1202) << "<<<<<<<<    ClosedTabItem::~ClosedTabItem("<< this << ") " << \
endl; +}
+
 KonqMainWindow::KonqMainWindow( const KUrl &initialURL, bool openInitialURL, const \
QString& xmluiFile)  : KParts::MainWindow()
 {
@@ -235,6 +261,10 @@
       KConfigGroup locationBarGroup( s_comboConfig, "Location Bar" );
       prov->load( locationBarGroup, "ComboIconCache" );
   }
+  
+  ClosedTabItem::setConfig( new KConfig( "konqueror_closedtabs" + \
QString::number(qHash(this)), KConfig::NoGlobals) ); +   kDebug(1202) << "--- \
closedTabs groupList: " << ClosedTabItem::config->groupList() << endl; +  
   connect( prov, SIGNAL( changed() ), SLOT( slotIconsChanged() ) );
 
   initCombo();
@@ -279,6 +309,7 @@
   m_paSaveViewPropertiesLocally->setChecked( m_bSaveViewPropertiesLocally );
 
   KonqUndoManager::incRef();
+  KonqUndoManager::self()->setClosedTabsList(m_closedTabsList);
 
   connect( KonqUndoManager::self(), SIGNAL( undoAvailable( bool ) ),
            this, SLOT( slotUndoAvailable( bool ) ) );
@@ -337,6 +368,7 @@
   delete m_paBookmarkBar;
   delete m_pBookmarksOwner;
   delete m_pURLCompletion;
+  delete m_paClosedTabs;
 
   KonqUndoManager::decRef();
 
@@ -1983,6 +2015,9 @@
         enable = true;
     }
   }
+  
+  if(!enable && !m_closedTabsList.isEmpty())
+  	enable = true;
 
   m_paUndo->setEnabled( enable );
 }
@@ -3086,11 +3121,61 @@
       KonqBidiHistoryAction::fillHistoryPopup( m_currentView->history(), \
m_currentView->historyIndex(), m_paBack->menu(), true, false );  }
 
+
+ /**
+  * Fill the closed tabs action menu before it's shown
+  */
+ void KonqMainWindow::slotClosedTabsListAboutToShow()
+ {
+   kDebug(1202) << "------------- KonqMainWindow::slotClosedTabsListAboutToShow() \
--------------" << endl; +   QMenu* popup = m_paClosedTabs->menu();
+   QString text, url;
+   kDebug(1202) << "--- closedTabs groupList: " << \
ClosedTabItem::config->groupList() << endl; +
+   // Clear the menu and fill it with a maximum of m_closedTabsListLength number of \
urls +   popup->clear();
+   if ( m_currentView )
+   {
+       QList<ClosedTabItem*>::ConstIterator it = m_closedTabsList.begin();
+       for ( uint i = 0; it != m_closedTabsList.end() && i++ < \
m_closedTabsListLength; ++it ) { +           text = (*it)->title;
+           url =  (*it)->url;
+           
+           popup->addAction( QIcon( KonqPixmapProvider::self()->pixmapFor( url)), \
text ); +       }
+   }
+  kDebug(1202) << "------------- KonqMainWindow::slotClosedTabsActivated done \
--------------" << endl; + }
+
 void KonqMainWindow::slotBack()
 {
   slotGoHistoryActivated(-1);
 }
 
+ /**
+  * Opens in a new tab the URL the user selected from the closed tabs menu and takes \
it from the list. +  *
+  * @param id Idetifier of the picked element in the menu
+  */
+ void KonqMainWindow::slotClosedTabsActivated( int id )
+ {
+  kDebug(1202) << "------------- KonqMainWindow::slotClosedTabsActivated() \
--------------" << endl; +  uint index = m_paClosedTabs->menu()->indexOf( id );
+  ClosedTabItem* closedTabItem = m_closedTabsList.at( index );
+  
+  m_pViewManager->openClosedTab( closedTabItem );
+  
+  m_closedTabsList.remove( closedTabItem );
+
+   // if there's no remaining closed tabs in the list,
+   // disable the action button
+   if(m_closedTabsList.isEmpty())
+   	m_paClosedTabs->setEnabled(false);
+  
+  kDebug(1202) << "------------- KonqMainWindow::slotClosedTabsActivated done \
--------------" << endl; + }
+
+
 void KonqMainWindow::slotBack(Qt::MouseButtons buttons, Qt::KeyboardModifiers \
modifiers)  {
   slotGoHistoryActivated( -1, buttons, modifiers );
@@ -3369,6 +3454,7 @@
 
       m_paTrash->setEnabled(false);
       m_paDelete->setEnabled(false);
+      m_paClosedTabs->setEnabled(false);
 
       slotClipboardDataChanged();
 
@@ -3724,6 +3810,21 @@
 
   QPair< KGuiItem, KGuiItem > backForward = KStandardGuiItem::backAndForward();
 
+
+    // Trash bin of closed tabs
+    m_paClosedTabs = new KToolBarPopupAction( KIcon("closedtabs"),  i18n( \
"closedtabs" ), this ); +    actionCollection()->addAction( "closedtabs", \
m_paClosedTabs ); +    // disabled by default. We need to do it with an instant \
single shot qtimer +    QTimer::singleShot( 0, this, SLOT(slotClosedTabsDisable()));
+    // set the maximum number of closed tabs list shown
+    connect( m_paClosedTabs, SIGNAL( triggered( Qt::MouseButtons, \
Qt::KeyboardModifiers) ), this, SLOT( slotOpenLastClosedTab() ) ); +    connect( \
m_paClosedTabs->menu(), SIGNAL( aboutToShow() ), this, SLOT( \
slotClosedTabsListAboutToShow() ) ); +    connect( m_paClosedTabs->menu(), SIGNAL( \
activated( int ) ), this, SLOT( slotClosedTabsActivated( int ) ) ); +    connect( \
m_pViewManager, SIGNAL( aboutToRemoveTab( KonqFrameBase *, KonqFrameTabs* ) ), this, \
SLOT( slotAddClosedUrl( KonqFrameBase *, KonqFrameTabs* ) ) ); +    
+    connect( KonqUndoManager::self(), SIGNAL( openClosedTab(ClosedTabItem *) ), \
this, SLOT( slotOpenLastClosedTab(ClosedTabItem *) ) ); +  
+
   m_paBack = new KToolBarPopupAction( KIcon(backForward.first.iconName()), \
backForward.first.text(), this );  actionCollection()->addAction( "back", m_paBack );
   m_paBack->setShortcuts( KStandardShortcut::shortcut(KStandardShortcut::Back) );
@@ -4045,6 +4146,10 @@
   m_paForward->setWhatsThis( i18n( "Move forward one step in the browsing \
history<p>" ) );  m_paForward->setToolTip( i18n( "Move forward one step in the \
browsing history" ) );  
+
+  m_paClosedTabs->setWhatsThis( i18n( "Move backwards one step in the closed tabs \
history<p>" ) ); +  m_paClosedTabs->setToolTip( i18n( "Move backwards one step in the \
closed tabs history" ) ); +
   m_paHome->setWhatsThis( i18n( "Navigate to your 'Home Location'<p>"
                                 "You can configure the location this button takes \
                you to in the "
                                 "<b>KDE Control Center</b>, under <b>File \
Manager</b>/<b>Behavior</b>." ) ); @@ -4144,6 +4249,12 @@
     m_pViewManager->moveTabForward();
 }
 
+
+void KonqMainWindow::slotClosedTabsDisable()
+{
+  m_paClosedTabs->setEnabled(false);
+}
+
 void KonqMainWindow::updateToolBarActions( bool pendingAction /*=false*/)
 {
   // Enables/disables actions that depend on the current view & url (mostly toolbar)
@@ -4486,6 +4597,7 @@
     m_paReload->setEnabled( false );
     m_paReloadAllTabs->setEnabled( false );
     m_paBack->setEnabled( false );
+    m_paClosedTabs->setEnabled( false );
     m_paForward->setEnabled( false );
     m_ptaUseHTML->setEnabled( false );
     m_pMenuNew->setEnabled( false );
@@ -4504,6 +4616,7 @@
     }
     // There are things we can do, though : bookmarks, view profile, location bar, \
new window,  // settings, etc.
+    m_paClosedTabs->setEnabled( true );
     m_paHome->setEnabled( true );
     m_pamBookmarks->setEnabled( true );
     static const char* const s_enActions[] = { "new_window", "duplicate_window", \
"open_location", @@ -4728,6 +4841,7 @@
   // It has to be a KActionCollection instead of a KActionPtrList because we need
   // the actionStatusText signal...
   KActionCollection popupMenuCollection( (QWidget*)0 );
+  popupMenuCollection.addAction( m_paClosedTabs->objectName(), m_paClosedTabs );
   popupMenuCollection.addAction( m_paBack->objectName(), m_paBack );
   popupMenuCollection.addAction( m_paForward->objectName(), m_paForward );
   popupMenuCollection.addAction( m_paUp->objectName(), m_paUp );
@@ -5417,6 +5531,92 @@
   QApplication::sendEvent( lineEdit, &event );
 }
 
+
+ /**
+  * Open last closed tab.
+  *
+  * If no tab has been closed yet (i.e. there's none in m_paClosedTabsList)
+  * then this methods does nothing.
+  */
+ void KonqMainWindow::slotOpenLastClosedTab(ClosedTabItem* closedTabItem)
+ {
+  kDebug(1202) << "---------------- KonqMainWindow::slotOpenLastClosedTab(" << \
closedTabItem << ") --------------" << endl; +  if(!closedTabItem)
+  {
+    closedTabItem = m_closedTabsList.first();
+    if(!closedTabItem)
+    {
+      kDebug(1202) << "!!! closedTabItem = 0L" << endl;
+      if(m_closedTabsList.isEmpty())
+        m_paClosedTabs->setEnabled(false);
+  
+      return;
+    }
+    m_closedTabsList.removeFirst();
+  }
+  
+  m_pViewManager->openClosedTab( closedTabItem );
+
+   // if there's no remaining closed tabs in the list,
+   // disable the action button
+   if(m_closedTabsList.isEmpty())
+   	m_paClosedTabs->setEnabled(false);
+  
+  kDebug(1202) << "---------------- KonqMainWindow::slotOpenLastClosedTab done \
--------------" << endl; + }
+ 
+ /**
+  * Adds the URL of a KonqView to the closed tabs list.
+  * This slot gets called everytime a View is closed
+  *
+  * @param view The KonqView that is getting closed
+  */
+ void KonqMainWindow::slotAddClosedUrl(KonqFrameBase *tab, KonqFrameTabs* \
tabContainer) + {
+  kDebug(1202) << "---------------- KonqViewManager::slotAddClosedUrl() \
--------------" << endl; +  KonqFrameBase* currentFrame = tab;
+  QString title( i18n("no name") ), url("about:blank");
+
+  KonqFrame* frame = dynamic_cast<KonqFrame *>(tab);
+  KonqFrameContainer* frame2 = dynamic_cast<KonqFrameContainer *>(tab);
+  
+  if ( frame && frame->activeChildView() )
+  {
+      title = frame->title().trimmed();
+      if ( title.isEmpty() )
+          title = frame->activeChildView()->url().url();
+      
+      title = KStringHandler::csqueeze( title, 50 );
+            
+      url = frame->activeChildView()->url().url();
+  } else if ( frame2 && frame2->activeChildView() )
+  {
+  	// TODO: in case we are a KonqFrameContainer.. how do we get the title of the \
selected view? +      title = frame2->activeChildView()->url().url();
+      
+      title = KStringHandler::csqueeze( title, 50 );
+            
+      url = frame2->activeChildView()->url().url();
+  }
+  
+  // Now we get the position of the tab
+  int index =  tabContainer->childFrameList()->indexOf(tab);
+  
+  ClosedTabItem* closedTabItem = new ClosedTabItem(url, tabContainer, title, index);
+  
+  kDebug(1202) << "GROUP: " << closedTabItem->getGroup() << endl;
+
+  QString prefix = QString::fromLatin1( currentFrame->frameType() ) + \
QString::number(0); +  closedTabItem->configGroup.writeEntry( "RootItem", prefix );
+  prefix.append( QLatin1Char( '_' ) );
+  currentFrame->saveConfig( closedTabItem->configGroup, prefix, true, 0L, 0, 1);
+  
+  m_paClosedTabs->setEnabled(true);
+  m_closedTabsList.prepend( closedTabItem );
+
+  kDebug(1202) << "------------- KonqViewManager::slotAddClosedUrl done \
--------------" << endl; + }
+
 void KonqMainWindow::slotLocationLabelActivated()
 {
   focusLocationBar();
Index: konqueror/konq_viewmgr.h
===================================================================
--- konqueror/konq_viewmgr.h	(revisión: 647756)
+++ konqueror/konq_viewmgr.h	(copia de trabajo)
@@ -1,5 +1,6 @@
 /*  This file is part of the KDE project
     Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
+    Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
 
     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
@@ -45,6 +46,7 @@
 class KonqView;
 class BrowserView;
 class KActionMenu;
+class ClosedTabItem;
 
 namespace KParts
 {
@@ -98,8 +100,12 @@
    */
   KonqView* addTab(const QString &serviceType = QString(),
                    const QString &serviceName = QString(),
-                   bool passiveMode = false, bool openAfterCurrentPage = false );
+                   bool passiveMode = false, bool openAfterCurrentPage = false, int \
pos = -1 );  
+  /**
+   * Opens a previously closed tab
+   */
+   void openClosedTab( ClosedTabItem* closedTab );
 
 
   /**
@@ -311,11 +317,14 @@
    *  (this is set to false when we have a forcedURL to open)
    */
   void loadItem( KConfigGroup &cfg, KonqFrameContainerBase *parent,
-                 const QString &name, const KUrl & defaultURL, bool openUrl, bool \
openAfterCurrentPage = false ); +                 const QString &name, const KUrl & \
defaultURL, bool openUrl, bool openAfterCurrentPage = false, int pos = -1 );  
   // Disabled - we do it ourselves
   virtual void setActiveComponent(const KComponentData &) {}
 
+ signals:
+  void aboutToRemoveTab( KonqFrameBase* tab, KonqFrameTabs* tabContainer );
+
 private:
 
   /**
@@ -340,7 +349,7 @@
                        const KService::List &partServiceOffers,
                        const KService::List &appServiceOffers,
                        const QString &serviceType,
-                       bool passiveMode, bool openAfterCurrentPage = false);
+                       bool passiveMode, bool openAfterCurrentPage = false, int pos \
= 0);  
 #ifndef NDEBUG
   //just for debugging
Index: konqueror/konqueror.rc
===================================================================
--- konqueror/konqueror.rc	(revisión: 647756)
+++ konqueror/konqueror.rc	(copia de trabajo)
@@ -64,6 +64,7 @@
   <Action name="go_most_often"/>
   <Separator/>
   <Action name="history"/>
+  <Action name="closedtabs"/>
  </Menu>
  <Action name="bookmarks"/>
  <Menu name="tools"><text>&amp;Tools</text>
@@ -121,6 +122,7 @@
  <Action name="stop"/>
  <Separator/>
  <Action name="print"/>
+ <Action name="closedtabs" />
  <WeakSeparator/>
  <Merge/>
  <Separator/>
Index: konqueror/konq_viewmgr.cc
===================================================================
--- konqueror/konq_viewmgr.cc	(revisión: 647756)
+++ konqueror/konq_viewmgr.cc	(copia de trabajo)
@@ -1,6 +1,7 @@
 // -*- mode: c++; c-basic-offset: 2 -*-
 /*  This file is part of the KDE project
     Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
+    Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
 
     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
@@ -33,10 +34,13 @@
 #include <kaccelgen.h>
 #include <kactionmenu.h>
 #include <kstandarddirs.h>
+#include <kstringhandler.h>
 #include <kdebug.h>
 #include <kapplication.h>
 #include <kglobalsettings.h>
+#include <konq_undo.h>
 #include <ktemporaryfile.h>
+#include <ktoolbarpopupaction.h>
 #include <klocale.h>
 #include <kmessagebox.h>
 
@@ -316,7 +320,7 @@
   m_pDocContainer = newContainer;
 }
 
-KonqView* KonqViewManager::addTab(const QString &serviceType, const QString \
&serviceName, bool passiveMode, bool openAfterCurrentPage  ) +KonqView* \
KonqViewManager::addTab(const QString &serviceType, const QString &serviceName, bool \
passiveMode, bool openAfterCurrentPage, int pos  )  {
 #ifdef DEBUG_VIEWMGR
   kDebug(1202) << "------------- KonqViewManager::addTab starting -------------" << \
endl; @@ -346,7 +350,7 @@
 
   if (m_pDocContainer->frameType() != "Tabs") convertDocContainer();
 
-  KonqView* childView = setupView( static_cast<KonqFrameTabs*>(m_pDocContainer), \
newViewFactory, service, partServiceOffers, appServiceOffers, serviceType, \
passiveMode, openAfterCurrentPage ); +  KonqView* childView = setupView( \
static_cast<KonqFrameTabs*>(m_pDocContainer), newViewFactory, service, \
partServiceOffers, appServiceOffers, serviceType, passiveMode, openAfterCurrentPage, \
pos );  
 #ifdef DEBUG_VIEWMGR
   m_pMainWindow->dumpViewList();
@@ -471,6 +475,61 @@
 #endif
 }
 
+ /**
+  * Opens in a new tab the URL the user selected from the closed tabs menu.
+  *
+  * @param id Idetifier of the picked element in the menu
+  */
+ void KonqViewManager::openClosedTab( ClosedTabItem* closedTab )
+ {
+ 
+  kDebug(1202) << "------------- KonqViewManager::openClosedTab( " << closedTab << \
") --------------" << endl; +  if(!closedTab)
+  {
+     return;
+  }
+  
+
+  kDebug(1202) << "A" << endl;
+  QString rootItem = closedTab->configGroup.readEntry( "RootItem", "empty" );
+
+  kDebug(1202) << "B" << endl;
+  if (rootItem.isNull() || rootItem == "empty")
+  {
+     delete closedTab;
+     return;
+  }
+  
+  // This flag is used by KonqView, to distinguish manual view creation
+  // from profile loading (e.g. in switchView)
+  m_bLoadingProfile = true;
+
+  loadItem( closedTab->configGroup, closedTab->tabContainer, rootItem, KUrl(""), \
true, false, closedTab->pos ); +  
+  if( closedTab->pos < closedTab->tabContainer->count() )
+     closedTab->tabContainer->setCurrentIndex( closedTab->pos );
+  else
+     closedTab->tabContainer->setCurrentIndex( closedTab->tabContainer->count()-1 );
+  
+  m_bLoadingProfile = false;
+
+  m_pMainWindow->enableAllActions(true);
+
+  // This flag disables calls to viewCountChanged while creating the views,
+  // so we do it once at the end :
+  viewCountChanged();
+
+
+   // delete the current closed tab, we don't need it anymore - we have just opened \
it! +   delete closedTab;
+   
+  kDebug(1202) << "------------- KonqViewManager::openClosedTab done --------------" \
<< endl; + }
+
+
+
+
+
 void KonqViewManager::breakOffTab( KonqFrameBase* tab )
 {
 #ifdef DEBUG_VIEWMGR
@@ -545,11 +604,11 @@
 
 void KonqViewManager::removeTab( KonqFrameBase* tab )
 {
-#ifdef DEBUG_VIEWMGR
+// #ifdef DEBUG_VIEWMGR
   kDebug(1202) << "---------------- KonqViewManager::removeTab( " << tab << " ) \
--------------" << endl;  m_pMainWindow->dumpViewList();
   printFullHierarchy( m_pMainWindow );
-#endif
+// #endif
 
   if (m_pDocContainer == 0L)
     return;
@@ -571,6 +630,8 @@
   if ( tabContainer->count() == 1 )
     return;
 
+  emit aboutToRemoveTab(currentFrame, tabContainer);
+
   if (currentFrame->asQWidget() == tabContainer->currentWidget())
     setActivePart( 0L, true );
 
@@ -1021,7 +1082,8 @@
                                       const KService::List &appServiceOffers,
                                       const QString &serviceType,
                                       bool passiveMode,
-                                      bool openAfterCurrentPage )
+                                      bool openAfterCurrentPage,
+                                      int pos )
 {
   kDebug(1202) << "KonqViewManager::setupView passiveMode=" << passiveMode << endl;
 
@@ -1052,6 +1114,8 @@
       KonqFrameTabs* tabContainer = static_cast<KonqFrameTabs*>(m_pDocContainer);
       if ( openAfterCurrentPage )
           index = tabContainer->currentIndex() +1 ;
+      else if(pos > -1)
+      	index = pos;
   }
 
   parentContainer->insertChildFrame( newViewFrame, index );
@@ -1443,7 +1507,8 @@
 }
 
 void KonqViewManager::loadItem( KConfigGroup &cfg, KonqFrameContainerBase *parent,
-                                const QString &name, const KUrl & defaultURL, bool \
openUrl, bool openAfterCurrentPage ) +                                const QString \
&name, const KUrl & defaultURL, bool openUrl, bool openAfterCurrentPage,  +           \
int pos )  {
   QString prefix;
   if( name != "InitialView" )
@@ -1479,7 +1544,7 @@
     bool passiveMode = cfg.readEntry( QString::fromLatin1( "PassiveMode" ).prepend( \
prefix ), false );  
     //kDebug(1202) << "KonqViewManager::loadItem: Creating View Stuff" << endl;
-    KonqView *childView = setupView( parent, viewFactory, service, \
partServiceOffers, appServiceOffers, serviceType, passiveMode, openAfterCurrentPage \
); +    KonqView *childView = setupView( parent, viewFactory, service, \
partServiceOffers, appServiceOffers, serviceType, passiveMode, openAfterCurrentPage, \
pos );  
     if (!childView->isFollowActive()) childView->setLinkedView( cfg.readEntry( \
                QString::fromLatin1( "LinkedView" ).prepend( prefix ), false ) );
     childView->setToggleView( cfg.readEntry( QString::fromLatin1( "ToggleView" \
).prepend( prefix ), false ) ); @@ -1598,7 +1663,7 @@
       KonqFrameContainer *newContainer = new KonqFrameContainer( o, \
                parent->asQWidget(), parent );
       connect(newContainer,SIGNAL(ctrlTabPressed()),m_pMainWindow,SLOT(slotCtrlTabPressed()));
  
-      int tabindex = -1;
+      int tabindex = pos;
       if(openAfterCurrentPage && parent->frameType() == "Tabs") // Need to honor it, \
if possible  tabindex = static_cast<KonqFrameTabs*>(parent)->currentIndex() + 1;
       parent->insertChildFrame( newContainer, tabindex );
Index: libkonq/konq_undo.cc
===================================================================
--- libkonq/konq_undo.cc	(revisión: 647756)
+++ libkonq/konq_undo.cc	(copia de trabajo)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE project
    Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
    Copyright (C) 2006 David Faure <faure@kde.org>
+   Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -62,9 +63,9 @@
  *
  */
 
-enum UndoState { MAKINGDIRS = 0, MOVINGFILES, STATINGFILE, REMOVINGDIRS, \
REMOVINGLINKS }; +enum UndoState { MAKINGDIRS = 0, MOVINGFILES, STATINGFILE, \
REMOVINGDIRS, REMOVINGLINKS, OPENINGTABS };  static const char* undoStateToString( \
                UndoState state ) {
-    static const char* s_undoStateToString[] = { "MAKINGDIRS", "MOVINGFILES", \
"STATINGFILE", "REMOVINGDIRS", "REMOVINGLINKS" }; +    static const char* \
s_undoStateToString[] = { "MAKINGDIRS", "MOVINGFILES", "STATINGFILE", "REMOVINGDIRS", \
"REMOVINGLINKS", "OPENINGTABS" };  return s_undoStateToString[state];
 }
 
@@ -169,7 +170,7 @@
     }
 
     bool m_syncronized;
-    bool m_lock;
+    Lock m_lock;
 
     KonqCommand::Stack m_commands;
 
@@ -200,7 +201,7 @@
 
     d = new KonqUndoManagerPrivate;
     d->m_syncronized = initializeFromKDesky();
-    d->m_lock = false;
+    d->m_lock = KonqUndoManager::OnlyUndoClosedTabs;
     d->m_currentJob = 0;
 }
 
@@ -235,6 +236,11 @@
     return s_self;
 }
 
+void KonqUndoManager::setClosedTabsList(QList<ClosedTabItem*> &closedTabsList)
+{
+	this->m_closedTabsList = &closedTabsList;
+}
+
 void KonqUndoManager::recordJob( CommandType op, const KUrl::List &src, const KUrl \
&dst, KIO::Job *job )  {
     // This records what the job does and calls addCommand when done
@@ -248,7 +254,11 @@
 
 bool KonqUndoManager::undoAvailable() const
 {
-    return ( d->m_commands.count() > 0 ) && !d->m_lock;
+    if(!m_closedTabsList->isEmpty())
+    {
+       return true;
+    } else
+       return ( d->m_commands.count() > 0 ) && d->m_lock == \
KonqUndoManager::OnlyUndoClosedTabs;  }
 
 QString KonqUndoManager::undoText() const
@@ -256,7 +266,13 @@
     if ( d->m_commands.isEmpty() )
         return i18n( "Und&o" );
 
-    KonqUndoManager::CommandType t = d->m_commands.top().m_type;
+    KonqUndoManager::CommandType t;
+    
+    if(d->m_lock == KonqUndoManager::Enabled && !m_closedTabsList->isEmpty()) {
+       t = getClosedTabCommand( m_closedTabsList->first() ).m_type;
+    } else
+       t = d->m_commands.top().m_type;
+    
     if ( t == KonqUndoManager::COPY )
         return i18n( "Und&o: Copy" );
     else if ( t == KonqUndoManager::LINK )
@@ -269,22 +285,57 @@
         return i18n( "Und&o: Trash" );
     else if ( t == KonqUndoManager::MKDIR )
         return i18n( "Und&o: Create Folder" );
+    else if ( t == KonqUndoManager::CLOSEDTAB )
+        return i18n( "Und&o: Close Tab" );
     else
         assert( false );
     /* NOTREACHED */
     return QString();
 }
 
+KonqCommand KonqUndoManager::getClosedTabCommand(ClosedTabItem* closedTab) const
+{
+    kDebug(1203) << "------------- KonqUndoManager::getClosedTab( " << closedTab << \
" ) --------------" << endl; +    if(d->m_commands.empty())
+       return KonqCommand();
+    
+    KonqCommand::Stack::Iterator it = d->m_commands.begin();
+    
+    for( ; it != d->m_commands.end(); ++it) {
+       if((*it).m_type == KonqUndoManager::CLOSEDTAB && (*it).m_closedTabItem == \
closedTab) +       {
+         kDebug(1203) << "tab: " << (*it).m_closedTabItem << endl;
+         return (*it);
+       }
+    }
+    
+    kDebug(1203) << "not found any tab" << endl;
+    kDebug(1203) << "------------- KonqUndoManager::lastClosedTab() --------------" \
<< endl; +    return KonqCommand();
+}
+
 void KonqUndoManager::undo()
 {
     // Make a copy of the command to undo before broadcastPop() pops it.
-    KonqCommand cmd = d->m_commands.top();
+    KonqCommand cmd;
+    if(d->m_lock == KonqUndoManager::Enabled && !m_closedTabsList->isEmpty())
+       cmd = getClosedTabCommand( m_closedTabsList->first() );
+    else
+       cmd = d->m_commands.top();
+
     assert( cmd.m_valid );
     d->m_current = cmd;
 
     KonqBasicOperation::Stack& opStack = d->m_current.m_opStack;
-    assert( !opStack.isEmpty() );
 
+    if(cmd.m_type == KonqUndoManager::CLOSEDTAB) {
+       d->m_undoState = OPENINGTABS;
+       
+       emit openClosedTab( 0L );
+    } else
+    	assert( !opStack.isEmpty() );
+
+
     // Let's first ask for confirmation if we need to delete any file (#99898)
     KUrl::List fileCleanupStack;
     QStack<KonqBasicOperation>::Iterator it = opStack.begin();
@@ -432,6 +483,7 @@
         d->m_undoState = MOVINGFILES;
 }
 
+
 // Misnamed method: It moves files back, but it also
 // renames directories back, recreates symlinks,
 // deletes copied files, and restores trashed files.
@@ -567,24 +619,46 @@
     emit undoTextChanged( undoText() );
 }
 
+void KonqUndoManager::removeClosedTab(ClosedTabItem* closedTabItem)
+{
+       KonqCommand::Stack::Iterator it = d->m_commands.begin();
+    
+       for( ; it != d->m_commands.end(); ++it) {
+          if((*it).m_type == KonqUndoManager::CLOSEDTAB && (*it).m_closedTabItem == \
closedTabItem) +          {
+            d->m_commands.erase(it);
+            kDebug(1203) << "pop tab: " << (*it).m_closedTabItem << endl;
+            emit undoAvailable( undoAvailable() );
+            emit undoTextChanged( undoText() );
+          }
+       }
+       kDebug(1203) << "pop: tab not found" << endl;
+}
+
 void KonqUndoManager::slotPop()
 {
-    d->m_commands.pop();
-    emit undoAvailable( undoAvailable() );
-    emit undoTextChanged( undoText() );
+    if(d->m_current.m_type != KonqUndoManager::CLOSEDTAB)
+    {
+       removeClosedTab(d->m_current.m_closedTabItem);
+    } else {
+       d->m_commands.pop();
+       emit undoAvailable( undoAvailable() );
+       emit undoTextChanged( undoText() );
+    }
+
 }
 
 void KonqUndoManager::slotLock()
 {
 //  assert( !d->m_lock );
-    d->m_lock = true;
+    d->m_lock = KonqUndoManager::Enabled;
     emit undoAvailable( undoAvailable() );
 }
 
 void KonqUndoManager::slotUnlock()
 {
 //  assert( d->m_lock );
-    d->m_lock = false;
+    d->m_lock = KonqUndoManager::OnlyUndoClosedTabs;
     emit undoAvailable( undoAvailable() );
 }
 
Index: libkonq/konq_undo.h
===================================================================
--- libkonq/konq_undo.h	(revisión: 647756)
+++ libkonq/konq_undo.h	(copia de trabajo)
@@ -2,6 +2,7 @@
 /* This file is part of the KDE project
    Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
    Copyright (C) 2006 David Faure <faure@kde.org>
+   Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -32,9 +33,11 @@
   class Job;
 }
 struct KonqBasicOperation;
+class ClosedTabItem;
 class KonqCommand;
 class KonqUndoJob;
 class KJob;
+class ClosedTabItem;
 
 /**
  * KonqUndoManager: makes it possible to undo kio jobs.
@@ -79,13 +82,19 @@
   };
 
   /**
+   * Must be called for initialization.
+   */
+  void setClosedTabsList(QList<ClosedTabItem*> &closedTabsList);
+
+  /**
    * Set a new UiInterface implementation.
    * This deletes the previous one.
    */
   void setUiInterface( UiInterface* ui );
 
-  enum CommandType { COPY, MOVE, RENAME, LINK, MKDIR, TRASH };
-
+  enum CommandType { COPY, MOVE, RENAME, LINK, MKDIR, TRASH, CLOSEDTAB };
+  typedef enum{Enabled, OnlyUndoClosedTabs} Lock;
+  
   /**
    * Record this job while it's happening and add a command for it so that the user \
                can undo it.
    * @param op the type of job - which is also the type of command that will be \
created for it @@ -94,7 +103,9 @@
    * @param job the job to record
    */
   void recordJob( CommandType op, const KUrl::List &src, const KUrl &dst, KIO::Job \
                *job );
-
+  
+  KonqCommand getClosedTabCommand(ClosedTabItem* closedTab) const;
+  void removeClosedTab(ClosedTabItem* closedTabItem);
   bool undoAvailable() const;
   QString undoText() const;
 
@@ -106,6 +117,8 @@
   /// @internal called by KonqUndoManagerAdaptor
   QByteArray get() const;
 
+  void pushCommand( const KonqCommand& cmd );
+
 Q_SIGNALS:
   /// Emitted when the value of undoAvailable() changes
   void undoAvailable( bool avail );
@@ -115,6 +128,9 @@
 
   /// Emitted when an undo job finishes. Used for unit testing.
   void undoJobFinished();
+  
+  /// Emitted when we want to open the last closed tab, because opening it is not \
our job +  void openClosedTab(ClosedTabItem* closedTabItem);
 
   // The four signals below are emitted to DBus
   void push( const QByteArray &command );
@@ -123,6 +139,7 @@
   void unlock();
 
 private Q_SLOTS:
+  
   // Those four are connected to DBUS signals
   void slotPush( QByteArray command ); // const ref doesn't work due to QDataStream
   void slotPop();
@@ -133,6 +150,7 @@
   void slotResult( KJob *job );
 
 private:
+  QList<ClosedTabItem*> *m_closedTabsList;
   KonqUndoManager();
 
   friend class KonqUndoJob;
@@ -143,13 +161,13 @@
   /// called by KonqCommandRecorder
   void addCommand( const KonqCommand &cmd );
 
-  void pushCommand( const KonqCommand& cmd );
   void undoStep();
 
   void stepMakingDirectories();
   void stepMovingFiles();
   void stepRemovingLinks();
   void stepRemovingDirectories();
+  void stepOpeningClosedTabs();
 
   void broadcastPush( const KonqCommand &cmd );
   void broadcastPop();
Index: libkonq/konq_undo_p.h
===================================================================
--- libkonq/konq_undo_p.h	(revisión: 647756)
+++ libkonq/konq_undo_p.h	(copia de trabajo)
@@ -1,6 +1,7 @@
 /* This file is part of the KDE project
    Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>
    Copyright (C) 2006 David Faure <faure@kde.org>
+   Copyright (C) 2007 Eduardo Robles Elvira <edulix@gmail.com>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -22,8 +23,11 @@
 #define KONQ_UNDO_P_H
 
 #include <qstack.h>
+#include <kdebug.h>
 #include <QUndoCommand>
 
+class ClosedTabItem;
+
 struct KonqBasicOperation
 {
     typedef QStack<KonqBasicOperation> Stack;
@@ -55,7 +59,7 @@
     typedef QStack<KonqCommand> Stack;
 
     KonqCommand()
-    { m_valid = false; }
+    { m_valid = false; m_closedTabItem = 0L; }
 
     // TODO
     //KonqCommand( Type type, KonqBasicOperation::Stack& opStack, const KUrl::List& \
src, const KUrl& dest ) @@ -74,6 +78,7 @@
 
     KonqUndoManager::CommandType m_type;
     KonqBasicOperation::Stack m_opStack;
+    ClosedTabItem* m_closedTabItem;
     KUrl::List m_src;
     KUrl m_dst;
 };



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic