Commit b7f8391d authored by Joachim Eibl's avatar Joachim Eibl

kdiff3fileitemactionplugin added (new contextmenu plugin for Dolphin and Konqueror)

git-svn-id: https://kdiff3.svn.sourceforge.net/svnroot/kdiff3/trunk@115 c8aa9fed-2811-0410-8543-893ada326672
parent c83ccb37
......@@ -4,8 +4,6 @@ project(kdiff3)
find_package(KDE4 REQUIRED)
include (MacroLibrary)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
MACRO_OPTIONAL_FIND_PACKAGE(LibKonq)
MACRO_BOOL_TO_01(LIBKONQ_FOUND HAVE_LIBKONQ)
add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
......@@ -24,15 +22,32 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kdiff3.h.cmake ${CMAKE_CURRENT
add_subdirectory(src-QT4)
add_subdirectory(po)
add_subdirectory(doc)
if(LIBKONQ_FOUND)
message(STATUS "")
message(STATUS "libkonq module found........... YES")
message(STATUS " => kdiff3plugin (KDiff3 contextmenu plugin for Konqueror) will be built.")
find_file(KFILEITEMACTIONPLUGIN_FOUND kfileitemactionplugin.h PATHS ${KDE4_INCLUDE_DIR} NO_DEFAULT_PATH)
if(KFILEITEMACTIONPLUGIN_FOUND)
message(STATUS "")
add_subdirectory(kdiff3plugin-QT4)
else(LIBKONQ_FOUND)
message(STATUS "kfileitemactionplugin.h found........... YES")
message(STATUS " => kdiff3fileitemactionplugin (KDiff3 contextmenu plugin for Konqueror/Dolphin, KDE>4.6) will be built.")
message(STATUS "")
message(STATUS "libkonq module found........... NO")
message(STATUS " => kdiff3plugin (KDiff3 contextmenu plugin for Konqueror) will not be built.)")
add_subdirectory(kdiff3fileitemactionplugin)
else(KFILEITEMACTIONPLUGIN_FOUND)
message(STATUS "")
endif(LIBKONQ_FOUND)
message(STATUS "kfileitemactionplugin.h found........... NO")
message(STATUS " => kdiff3fileitemactionplugin (KDiff3 contextmenu plugin for Konqueror/Dolphin, KDE>4.6) will not be built.)")
message(STATUS "Trying fallback via libkonq (works with Konqueror only) ...")
MACRO_OPTIONAL_FIND_PACKAGE(LibKonq)
MACRO_BOOL_TO_01(LIBKONQ_FOUND HAVE_LIBKONQ)
if(LIBKONQ_FOUND)
message(STATUS "")
message(STATUS "libkonq module found........... YES")
message(STATUS " => kdiff3plugin (KDiff3 contextmenu plugin for Konqueror) will be built.")
message(STATUS "")
add_subdirectory(kdiff3plugin-QT4)
else(LIBKONQ_FOUND)
message(STATUS "")
message(STATUS "libkonq module found........... NO")
message(STATUS " => kdiff3plugin (KDiff3 contextmenu plugin for Konqueror) will not be built.)")
message(STATUS "")
endif(LIBKONQ_FOUND)
endif(KFILEITEMACTIONPLUGIN_FOUND)
kde4_add_plugin(kdiff3fileitemaction kdiff3fileitemaction.cpp)
target_link_libraries(kdiff3fileitemaction ${KDE4_KIO_LIBS} ${LibKDiff3_LIBRARIES})
install(TARGETS kdiff3fileitemaction DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES kdiff3fileitemaction.desktop DESTINATION ${SERVICES_INSTALL_DIR})
/* This file is part of the KDiff3 project
Copyright (C) 2008 Joachim Eibl <joachim dot eibl at gmx dot de>
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; version 2
of the License.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "kdiff3fileitemaction.h"
#include <kapplication.h>
#include <kstandarddirs.h>
#include <QAction>
#include <QMenu>
#include <klocale.h>
#include <kgenericfactory.h>
#include <kurl.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kfileitem.h>
//#include <iostream>
static QStringList* s_pHistory=0;
class KDiff3PluginHistory
{
KConfig* m_pConfig;
KConfigGroup* m_pConfigGroup;
public:
KDiff3PluginHistory()
{
m_pConfig = 0;
if (s_pHistory==0)
{
//std::cout << "New History: " << instanceName << std::endl;
s_pHistory = new QStringList;
m_pConfig = new KConfig( "kdiff3fileitemactionrc", KConfig::SimpleConfig );
m_pConfigGroup = new KConfigGroup( m_pConfig, "KDiff3Plugin" );
*s_pHistory = m_pConfigGroup->readEntry("HistoryStack", QStringList() );
}
}
~KDiff3PluginHistory()
{
//std::cout << "Delete History" << std::endl;
if ( s_pHistory && m_pConfigGroup )
m_pConfigGroup->writeEntry("HistoryStack",*s_pHistory);
delete s_pHistory;
delete m_pConfigGroup;
delete m_pConfig;
s_pHistory = 0;
m_pConfig = 0;
}
};
static KDiff3PluginHistory s_history;
K_PLUGIN_FACTORY(KDiff3FileItemActionFactory, registerPlugin<KDiff3FileItemAction>();)
K_EXPORT_PLUGIN(KDiff3FileItemActionFactory("KDiff3FileItemAction"))
KDiff3FileItemAction::KDiff3FileItemAction (QObject* pParent, const QVariantList & /*args*/)
: KFileItemActionPlugin(pParent)
{
}
QList<QAction*> KDiff3FileItemAction::actions( const KFileItemListProperties& fileItemInfos, QWidget* pParentWidget ) const
{
QList< QAction* > actions;
if (KStandardDirs::findExe("kdiff3").isNull ())
return actions;
KDiff3FileItemAction *pThis = const_cast<KDiff3FileItemAction*>(this);
//pThis->m_fileItemInfos = fileItemInfos;
pThis->m_pParentWidget = pParentWidget;
QAction *pMenuAction = new QAction(KIcon("kdiff3"), i18n("KDiff3 ..."), pThis);
QMenu *pActionMenu = new QMenu();
pMenuAction->setMenu( pActionMenu );
// remember currently selected files (copy to a QStringList)
KUrl::List itemList = fileItemInfos.urlList();
foreach ( const KUrl& item, itemList )
{
//m_urlList.append( item.url() );
pThis->m_list.append( item.url() );
}
/* Menu structure:
KDiff3 -> (1 File selected): Save 'selection' for later comparison (push onto history stack)
Compare 'selection' with first file on history stack.
Compare 'selection' with -> choice from history stack
Merge 'selection' with first file on history stack.
Merge 'selection' with last two files on history stack.
(2 Files selected): Compare 's1' with 's2'
Merge 's1' with 's2'
(3 Files selected): Compare 's1', 's2' and 's3'
*/
QAction* pAction = 0;
QString s;
if(m_list.count() == 1)
{
int historyCount = s_pHistory ? s_pHistory->count() : 0;
s = i18n("Compare with %1", (historyCount>0 ? s_pHistory->front() : QString()) );
pAction = new QAction ( s,pThis );
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotCompareWith()));
pAction->setEnabled( m_list.count()>0 && historyCount>0 );
pActionMenu->addAction(pAction);
s = i18n("Merge with %1", historyCount>0 ? s_pHistory->front() : QString() );
pAction = new QAction( s, pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotMergeWith()));
pAction->setEnabled( m_list.count()>0 && historyCount>0 );
pActionMenu->addAction (pAction);
s = i18n("Save '%1' for later", ( m_list.front() ) );
pAction = new QAction ( s, pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotSaveForLater()));
pAction->setEnabled( m_list.count()>0 );
pActionMenu->addAction(pAction);
pAction = new QAction (i18n("3-way merge with base"), pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotMergeThreeWay()));
pAction->setEnabled( m_list.count()>0 && historyCount>=2 );
pActionMenu->addAction (pAction);
if ( s_pHistory && !s_pHistory->empty() )
{
QAction* pHistoryMenuAction = new QAction( i18n("Compare with ..."), pThis );
QMenu* pHistoryMenu = new QMenu();
pHistoryMenuAction->setMenu( pHistoryMenu );
pHistoryMenu->setEnabled( m_list.count()>0 && historyCount>0 );
pActionMenu->addAction(pHistoryMenuAction);
for (QStringList::iterator i = s_pHistory->begin(); i!=s_pHistory->end(); ++i)
{
pAction = new QAction( *i, pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotCompareWithHistoryItem()));
pHistoryMenu->addAction (pAction);
}
pAction = new QAction (i18n("Clear list"), pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotClearList()));
pActionMenu->addAction (pAction);
pAction->setEnabled( historyCount>0 );
}
}
else if(m_list.count() == 2)
{
pAction = new QAction (i18n("Compare"), pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotCompareTwoFiles()));
pActionMenu->addAction (pAction);
}
else if ( m_list.count() == 3 )
{
pAction = new QAction (i18n("3 way comparison"), pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotCompareThreeFiles()));
pActionMenu->addAction (pAction);
}
pAction = new QAction (i18n("About KDiff3 menu plugin ..."), pThis);
connect( pAction, SIGNAL(triggered(bool)), this, SLOT(slotAbout()));
pActionMenu->addAction (pAction);
//pMenu->addSeparator();
//pMenu->addAction( pActionMenu );
//pMenu->addSeparator();
actions << pMenuAction;
return actions;
}
KDiff3FileItemAction::~KDiff3FileItemAction ()
{
}
void KDiff3FileItemAction::slotCompareWith()
{
if ( m_list.count() > 0 && s_pHistory && ! s_pHistory->empty() )
{
QStringList args;
args << s_pHistory->front();
args << m_list.front();
KProcess::startDetached("kdiff3", args);
}
}
void KDiff3FileItemAction::slotCompareWithHistoryItem()
{
const QAction* pAction = dynamic_cast<const QAction*>( sender() );
if ( m_list.count() > 0 && pAction )
{
QStringList args;
args << pAction->text();
args << m_list.front();
KProcess::startDetached ("kdiff3", args);
}
}
void KDiff3FileItemAction::slotCompareTwoFiles()
{
if ( m_list.count() == 2 )
{
QStringList args;
args << m_list.front();
args << m_list.back();
KProcess::startDetached ("kdiff3", args);
}
}
void KDiff3FileItemAction::slotCompareThreeFiles()
{
if ( m_list.count() == 3 )
{
QStringList args;
args << m_list[0];
args << m_list[1];
args << m_list[2];
KProcess::startDetached ("kdiff3", args);
}
}
void KDiff3FileItemAction::slotMergeWith()
{
if ( m_list.count() > 0 && s_pHistory && ! s_pHistory->empty() )
{
QStringList args;
args << s_pHistory->front();
args << m_list.front();
args << ( "-o" + m_list.front() );
KProcess::startDetached ("kdiff3", args);
}
}
void KDiff3FileItemAction::slotMergeThreeWay()
{
if ( m_list.count() > 0 && s_pHistory && s_pHistory->count()>=2 )
{
QStringList args;
args << (*s_pHistory)[1];
args << (*s_pHistory)[0];
args << m_list.front();
args << ("-o" + m_list.front());
KProcess::startDetached ("kdiff3", args);
}
}
void KDiff3FileItemAction::slotSaveForLater()
{
if ( !m_list.isEmpty() && s_pHistory )
{
while ( s_pHistory->count()>=10 )
s_pHistory->pop_back();
s_pHistory->push_front( m_list.front() );
}
}
void KDiff3FileItemAction::slotClearList()
{
if ( s_pHistory )
s_pHistory->clear();
}
void KDiff3FileItemAction::slotAbout()
{
QString s = i18n("KDiff3 File Item Action Plugin: Copyright (C) 2011 Joachim Eibl\n"
"KDiff3 homepage: http://kdiff3.sourceforge.net\n\n");
s += i18n("Using the contextmenu extension:\n"
"For simple comparison of two selected files choose \"Compare\".\n"
"If the other file is somewhere else \"Save\" the first file for later. "
"It will appear in the \"Compare With ...\" submenu. "
"Then use \"Compare With\" on second file.\n"
"For a 3-way merge first \"Save\" the base file, then the branch to merge and "
"choose \"3-way merge with base\" on the other branch which will be used as destination.\n"
"Same also applies to directory comparison and merge.");
KMessageBox::information(m_pParentWidget, s, tr("About KDiff3 File Item Action Plugin") );
}
[Desktop Entry]
Encoding=UTF-8
Type=Service
Name=Compare/Merge Files/Directories with KDiff3
Name[bg]=Сравняване/Сливане на файлове/директории с KDiff3
Name[cs]=Porovnat/spojit soubory/adresáře pomocí KDiff3
Name[de]=Dateien und Ordner vergleichen und zusammenführen mit KDiff3
Name[el]=Σύγκριση/Συγχώνευση αρχείων/καταλόγων με το KDiff3
Name[es]=Comparar/fusionar archivos/directorios con KDiff3
Name[et]=Failide/kataloogide võrdlemine/liitmine KDiff3-ga
Name[fr]=Comparer / Fusionner les fichiers / dossiers à l'aide de KDiff3
Name[ga]=Comhaid/Comhadlanna a Chur i gComparáid/a Chumasc le KDiff3
Name[gl]=Compara e fusionar ficheiros e cartafoles con KDiff3
Name[hi]=केडिफ़३ के साथ तुलना करें/मिलाएं फ़ाइलें/डिरेक्ट्रीज़
Name[ja]=KDiff3 でファイルやディレクトリを比較/マージ
Name[km]=ប្រៀបធៀប/បញ្ចូល​ឯកសារ​ចូល​គ្នា/ថត​ជាមួយ KDiff3
Name[ko]=KDiff3으로 파일과 디렉터리를 비교하거나 병합합니다
Name[nds]=Verglieken Tosamenföhren vun Dateien/Ornern mit KDiff3
Name[nl]=Bestanden/mappen vergelijken/samenvoegen met KDiff3
Name[nn]=Samanlikn/flett filer og mapper med KDiff3
Name[pt]=Comparar/Juntar os Ficheiros/Pastas com o KDiff3
Name[pt_BR]=Compara/Mescla Arquivos/Diretórios com KDiff3
Name[ro]=Compară/unește fișiere/directoare cu KDiff3
Name[sv]=Jämför, sammanfoga filer, kataloger med Kdiff3
Name[tr]=KDiff3 ile Dosyaları/Klasörleri Karşılaştır/Birleştir
Name[uk]=Порівнюйте або з’єднуйте файли або теки з KDiff3
Name[x-test]=xxCompare/Merge Files/Directories with KDiff3xx
Name[zh_CN]=使用 KDiff3 比较/合并 文件/目录
Name[zh_TW]=用 KDiff3 比較/合併檔案與目錄
X-KDE-Library=kdiff3fileitemaction
X-KDE-Submenu=KDiff3
ServiceTypes=KFileItemAction/Plugin
MimeType=application/octet-stream;
/* This file is part of the KDiff3 project
Copyright (C) 2008 Joachim Eibl <Joachim dot Eibl at gmx dot de>
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; version 2
of the License.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef _KDIFF3FILEITEMACTIONPLUGIN_H_
#define _KDIFF3FILEITEMACTIONPLUGIN_H_
#include <kfileitemactionplugin.h>
#include <kfileitemlistproperties.h>
#include <QStringList>
class QStringList;
class KDiff3FileItemAction : public KFileItemActionPlugin
{
Q_OBJECT
public:
KDiff3FileItemAction (QObject* pParent, const QVariantList & args);
virtual ~KDiff3FileItemAction();
// implement pure virtual method from KonqPopupMenuPlugin
virtual QList<QAction*> actions( const KFileItemListProperties& fileItemInfos, QWidget* pParentWidget ) const;
private slots:
void slotCompareWith();
void slotCompareTwoFiles();
void slotCompareThreeFiles();
void slotMergeWith();
void slotMergeThreeWay();
void slotSaveForLater();
void slotClearList();
void slotCompareWithHistoryItem();
void slotAbout();
private:
QStringList m_list;
QWidget* m_pParentWidget;
//KFileItemListProperties m_fileItemInfos;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment