Remove kpartapp template, variant has been added to kparts itself

parent 8a032d02
set(APPTEMPLATE_DIRS
kde-frameworks5-simple
kde-frameworks5
kpartapp
akonadiresource
akonadiserializer
)
......
cmake_minimum_required(VERSION 2.8.12)
project(%{APPNAMELC})
find_package(ECM 1.0.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMInstallIcons)
include(FeatureSummary)
set(QT_MIN_VERSION "5.6.0")
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets)
set(REQUIRED_KF5_VERSION "5.18.0")
find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED COMPONENTS
Crash
DBusAddons
I18n
Parts
)
#add_subdirectory( doc )
add_subdirectory( src )
add_subdirectory( icons )
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
How To Build This Template
-=-=-=-=-=-=-=-=-=-=-=-=-=
--- On Unix:
cd <project_name_path>
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$KDEDIRS -DCMAKE_BUILD_TYPE=Debug .. <- do not forget the ..
make
make install or su -c 'make install'
where $KDEDIRS points to your KDE installation prefix.
to uninstall the project:
make uninstall or su -c 'make uninstall'
Note: you can use another build path. Then cd in your build dir and:
export KDE_SRC=path_to_your_src
cmake $KDE_SRC -DCMAKE_INSTALL_PREFIX=$KDEDIRS -DCMAKE_BUILD_TYPE=Debug
--- On Windows:
cd <project_name_path>
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=%KDEDIRS% -DCMAKE_BUILD_TYPE=Debug .. <- do not forget the ..
[n]make
[n]make install
where %KDEDIRS% points to your KDE installation prefix.
to uninstall the project:
[n]make uninstall
Note: use nmake if you're building with the Visual Studio compiler, or make
if you're using the minGW compiler
Tutorials
-=-=-=-=-
Kpart docs
https://techbase.kde.org/Development/Architecture/KDE4/KParts
https://api.kde.org/frameworks/kparts/html/index.html
Tutorial
https://techbase.kde.org/Development/Tutorials/Using_KParts
----------------------------
Please send all comments to:
Anne-Marie Mahfouf
annma@kde.org
Last update: July 2009
\ No newline at end of file
kdoctools_create_handbook(index.docbook INSTALL_DESTINATION ${KDE_INSTALL_DOCBUNDLEDIR}/en SUBDIR %{APPNAMELC})
How to add a documentation to your project:
* copy a template from frameworks/kdoctools/src to this directory
- article-template.docbook -> article for a short documentation e.g. for a plugin
- template.docbook -> book template for an application
rename the template to index.docbook
edit the content of index.docbook, never use an unmodified template
if you need help with the docbook format mail to the documentation team (kde-doc-english@kde.org)
* if your documentation is finished, add the doc directory to the CMakeLists.txt in the parent dir
(uncomment the line "#add_subdirectory( doc )"
* to get your documentation into the translation process, mail to the translation team (kde-i18n-doc@kde.org)
set(%{APPNAMELC}_ICONS
16-apps-%{APPNAMELC}.png
32-apps-%{APPNAMELC}.png
48-apps-%{APPNAMELC}.png
)
ecm_install_icons(ICONS ${%{APPNAMELC}_ICONS} DESTINATION ${KDE_INSTALL_ICONDIR} THEME hicolor)
# KDE Config File
[General]
Name=KPart Application
Name[ca]=Aplicació KPart
Name[ca@valencia]=Aplicació KPart
Name[es]=Aplicación KPart
Name[nl]=KPart-toepassing
Name[pt]=Aplicação KPart
Name[sk]=KPart aplikácia
Name[sr]=К‑деони програм
Name[sr@ijekavian]=К‑диони програм
Name[sr@ijekavianlatin]=K‑dioni program
Name[sr@latin]=K‑deoni program
Name[sv]=KPart-program
Name[uk]=Програма KPart
Name[x-test]=xxKPart Applicationxx
Comment=KPart Application. Simple template based on CMake, inherits from KParts/MainWindow and demonstrates how to use KPart
Comment[ca]=Aplicació KPart. Plantilla simple basada en el CMake, hereva del KParts/MainWindow i que demostra com usar la KPart
Comment[ca@valencia]=Aplicació KPart. Plantilla simple basada en el CMake, hereva del KParts/MainWindow i que demostra com usar la KPart
Comment[es]=Aplicación KPart. Sencilla plantilla basada en CMake, que hereda de KParts/MainWindow y demuestra cómo usar KPart
Comment[nl]=KPart-toepassing. Eenvoudig sjabloon gebaseerd op CMake, afkomstig van KParts/MainWindow en demonstreert hoe u KPart kunt gebruiken
Comment[pt]=Aplicação KPart. Um modelo simples com base no CMake, que herda do KParts/MainWindow e demonstra como utilizar o KPart
Comment[sk]=Aplikácia KPart. Jednoduchá šablóna založená na CMake, dedí od KParts/MainWindow a demonštruje, ako používať KPart
Comment[sr]=Једноставан шаблон на основу Ц‑мејка, наслеђује KParts/MainWindow и показује извођење К‑дела
Comment[sr@ijekavian]=Једноставан шаблон на основу Ц‑мејка, насљеђује KParts/MainWindow и показује извођење К‑дијела
Comment[sr@ijekavianlatin]=Jednostavan šablon na osnovu CMakea, nasljeđuje KParts/MainWindow i pokazuje izvođenje K‑dijela
Comment[sr@latin]=Jednostavan šablon na osnovu CMakea, nasleđuje KParts/MainWindow i pokazuje izvođenje K‑dela
Comment[sv]=KPart-program. Enkel mall baserad på CMake, ärver KParts/MainWindow och demonstrerar hur man använder KPart
Comment[uk]=Програма KPart. Простий шаблон, заснований на CMake, успадковує клас KParts/MainWindow і демонструє використання KPart
Comment[x-test]=xxKPart Application. Simple template based on CMake, inherits from KParts/MainWindow and demonstrates how to use KPartxx
Category=Qt/Graphical
Icon=kpartapp.png
ShowFilesAfterGeneration=%{dest}/src/%{APPNAMELC}.cpp
/***************************************************************************
* Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
* *
* 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; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "%{APPNAMELC}.h"
// KF headers
#include <KParts/ReadWritePart>
#include <KPluginLoader>
#include <KPluginFactory>
#include <KActionCollection>
#include <KConfigGroup>
#include <KMessageBox>
#include <KStandardAction>
#include <KLocalizedString>
// Qt headers
#include <QApplication>
#include <QFileDialog>
#include <QAction>
%{APPNAME}::%{APPNAME}()
: KParts::MainWindow( )
{
// set the shell's ui resource file
setXMLFile(QStringLiteral("%{APPNAMELC}_shell.rc"));
// then, setup our actions
setupActions();
// this routine will find and load our Part. it finds the Part by
// name which is a bad idea usually.. but it's alright in this
// case since our Part is made for this Shell
KPluginLoader loader(QStringLiteral("%{APPNAMELC}part"));
KPluginFactory* factory = loader.factory();
if (factory) {
// now that the Part is loaded, we cast it to a Part to get
// our hands on it
m_part = factory->create<KParts::ReadWritePart>(this);
if (m_part) {
// tell the KParts::MainWindow that this is indeed the main widget
setCentralWidget(m_part->widget());
// and integrate the part's GUI with the shell's
setupGUI(ToolBar | Keys | StatusBar | Save);
createGUI(m_part);
}
} else {
// if we couldn't find our Part, we exit since the Shell by
// itself can't do anything useful
KMessageBox::error(this, i18n("Could not find our Part!"));
qApp->quit();
// we return here, cause qApp->quit() only means "exit the
// next time we enter the event loop...
return;
}
}
%{APPNAME}::~%{APPNAME}()
{
}
void %{APPNAME}::load(const QUrl& url)
{
m_part->openUrl(url);
}
void %{APPNAME}::setupActions()
{
KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
}
void %{APPNAME}::saveProperties(KConfigGroup & /*config*/)
{
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
}
void %{APPNAME}::readProperties(const KConfigGroup & /*config*/)
{
// the 'config' object points to the session managed
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
}
void %{APPNAME}::fileNew()
{
// this slot is called whenever the File->New menu is selected,
// the New shortcut is pressed (usually CTRL+N) or the New toolbar
// button is clicked
// About this function, the style guide (
// http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
// says that it should open a new window if the document is _not_
// in its initial state. This is what we do here..
if (!m_part->url().isValid() || m_part->isModified()) {
(new %{APPNAME})->show();
};
}
void %{APPNAME}::fileOpen()
{
// this slot is called whenever the File->Open menu is selected,
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
const QUrl url = QFileDialog::getOpenFileUrl(this);
if (url.isValid()) {
// About this function, the style guide (
// http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
// says that it should open a new window if the document is _not_
// in its initial state. This is what we do here..
if (m_part->url().isEmpty() && ! m_part->isModified()) {
// we open the file in this window...
load(url);
} else {
// we open the file in a new window...
%{APPNAME}* newWin = new %{APPNAME};
newWin->load(url);
newWin->show();
}
}
}
[Desktop Entry]
Name=%{APPNAME}
Name[bg]=%{APPNAME}
Name[bs]=%{APPNAME}
Name[ca]=%{APPNAME}
Name[ca@valencia]=%{APPNAME}
Name[cs]=%{APPNAME}
Name[da]=%{APPNAME}
Name[de]=%{APPNAME}
Name[el]=%{APPNAME}
Name[en_GB]=%{APPNAME}
Name[eo]=%{APPNAME}
Name[es]=%{APPNAME}
Name[et]=%{APPNAME}
Name[fi]=%{APPNAME}
Name[fr]=%{APPNAME}
Name[ga]=%{APPNAME}
Name[gl]=%{APPNAME}
Name[hu]=%{APPNAME}
Name[it]=%{APPNAME}
Name[ja]=%{APPNAME}
Name[kk]=%{APPNAME}
Name[km]=%{APPNAME}
Name[ko]=%{APPNAME}
Name[lt]=%{APPNAME}
Name[lv]=%{APPNAME}
Name[nb]=%{APPNAME}
Name[nds]=%{APPNAME}
Name[nl]=%{APPNAME}
Name[nn]=%{APPNAME}
Name[pa]=%{APPNAME}
Name[pl]=%{APPNAME}
Name[pt]=%{APPNAME}
Name[pt_BR]=%{APPNAME}
Name[ro]=%{APPNAME}
Name[ru]=%{APPNAME}
Name[sk]=%{APPNAME}
Name[sl]=%{APPNAME}
Name[sq]=%{APPNAME}
Name[sr]=%{APPNAME}
Name[sr@ijekavian]=%{APPNAME}
Name[sr@ijekavianlatin]=%{APPNAME}
Name[sr@latin]=%{APPNAME}
Name[sv]=%{APPNAME}
Name[tr]=%{APPNAME}
Name[ug]=%{APPNAME}
Name[uk]=%{APPNAME}
Name[x-test]=xx%{APPNAME}xx
Name[zh_CN]=%{APPNAME}
Name[zh_TW]=%{APPNAME}
Exec=%{APPNAMELC} -qwindowicon %{APPNAMELC} -qwindowtitle %c
Icon=%{APPNAMELC}
Type=Application
X-DocPath=%{APPNAMELC}/index.html
GenericName=A KPart Application
GenericName[ca]=Una aplicació KPart
GenericName[ca@valencia]=Una aplicació KPart
GenericName[es]=Una aplicación KPart
GenericName[nl]=Een KPart-toepassing
GenericName[pt]=Uma Aplicação KPart
GenericName[sk]=KPart aplikácia
GenericName[sr]=К‑деони програм
GenericName[sr@ijekavian]=К‑диони програм
GenericName[sr@ijekavianlatin]=K‑dioni program
GenericName[sr@latin]=K‑deoni program
GenericName[sv]=Ett KPart-program
GenericName[uk]=Програма KPart
GenericName[x-test]=xxA KPart Applicationxx
Terminal=false
/***************************************************************************
* Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
* *
* 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; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef %{APPNAMEUC}_H
#define %{APPNAMEUC}_H
// KF headers
#include <KParts/MainWindow>
namespace KParts {
class ReadWritePart;
}
/**
* This is the application "Shell". It has a menubar, toolbar, and
* statusbar but relies on the "Part" to do all the real work.
*
* @short Application Shell
*/
class %{APPNAME} : public KParts::MainWindow
{
Q_OBJECT
public:
/**
* Default Constructor
*/
%{APPNAME}();
/**
* Default Destructor
*/
~%{APPNAME}() override;
/**
* Use this method to load whatever file/URL you have
*/
void load(const QUrl& url);
protected:
/**
* This method is called when it is time for the app to save its
* properties for session management purposes.
*/
void saveProperties(KConfigGroup &) override;
/**
* This method is called when this app is restored. The KConfig
* object points to the session management config file that was saved
* with @ref saveProperties
*/
void readProperties(const KConfigGroup &) override;
private Q_SLOTS:
void fileNew();
void fileOpen();
private:
void setupActions();
private:
KParts::ReadWritePart *m_part;
};
#endif // %{APPNAMEUC}_H
/***************************************************************************
* Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
* *
* 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; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "%{APPNAMELC}_part.h"
// KF headers
#include <KAboutData>
#include <KLocalizedString>
#include <KActionCollection>
#include <KPluginFactory>
#include <KStandardAction>
// Qt headers
#include <QFileDialog>
#include <QFile>
#include <QTextStream>
#include <QTextEdit>
#include <QTextDocument>
K_PLUGIN_FACTORY(%{APPNAME}PartFactory, registerPlugin<%{APPNAME}Part>();)
%{APPNAME}Part::%{APPNAME}Part(QWidget *parentWidget, QObject *parent, const QVariantList & /*args*/)
: KParts::ReadWritePart(parent)
{
// we need a component data
// the first arg here must be the same as the subdirectory in
// which the part's rc file is installed
KAboutData aboutData("%{APPNAMELC}part", i18n("%{APPNAME}Part"), QStringLiteral("%{VERSION}"));
aboutData.addAuthor(i18n("%{AUTHOR}"), i18n("Author"), QStringLiteral("%{EMAIL}"));
setComponentData(aboutData);
// this should be your custom internal widget
m_widget = new QTextEdit(parentWidget);
// notify the part that this is our internal widget
setWidget(m_widget);
// create our actions
m_saveAction = KStandardAction::save(this, SLOT(fileSave()), actionCollection());
KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
// set our XML-UI resource file
setXMLFile("%{APPNAMELC}_part.rc");
// we are read-write by default
setReadWrite(true);
// we are not modified since we haven't done anything yet
setModified(false);
}
%{APPNAME}Part::~%{APPNAME}Part()
{
}
void %{APPNAME}Part::setReadWrite(bool rw)
{
// notify your internal widget of the read-write state
m_widget->setReadOnly(!rw);
QTextDocument* document = m_widget->document();
if (rw) {
connect(document, &QTextDocument::modificationChanged,
this, &%{APPNAME}Part::setModified);
} else {
disconnect(document, &QTextDocument::modificationChanged,
this, &%{APPNAME}Part::setModified);
}
ReadWritePart::setReadWrite(rw);
}
void %{APPNAME}Part::setModified(bool modified)
{
// get a handle on our Save action and make sure it is valid
if (!m_saveAction) {
return;
}
// if so, we either enable or disable it based on the current
// state
m_saveAction->setEnabled(modified);
// in any event, we want our parent to do it's thing
ReadWritePart::setModified(modified);
}
bool %{APPNAME}Part::openFile()
{
// localFilePath() is always local so we can use QFile on it
QFile file(localFilePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return false;
}
// our example widget is text-based, so we use QTextStream instead
// of a raw QDataStream
QTextStream stream(&file);
QString str;
while (!stream.atEnd()) {
str += stream.readLine() + "\n";
}
file.close();
// now that we have the entire file, display it
m_widget->setPlainText(str);
// just for fun, set the status bar
//emit setStatusBarText( m_url.prettyUrl() );
return true;
}
bool %{APPNAME}Part::saveFile()
{
// if we aren't read-write, return immediately
if (!isReadWrite()) {
return false;
}
// localFilePath() is always local, so we use QFile
QFile file(localFilePath());
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
return false;
}
// use QTextStream to dump the text to the file
QTextStream stream(&file);
stream << m_widget->toPlainText();
file.close();
m_widget->document()->setModified(false);
return true;
}
void %{APPNAME}Part::fileSave()
{
if (url().isValid()) {
save();
} else {
fileSaveAs();
}
}
void %{APPNAME}Part::fileSaveAs()
{
// this slot is called whenever the File->Save As menu is selected,
const QUrl file_name = QFileDialog::getSaveFileUrl();
if (file_name.isValid()) {
saveAs(file_name);
}
}
// needed for K_PLUGIN_FACTORY
#include "%{APPNAMELC}_part.moc"
[Desktop Entry]
Type=Service
Icon=%{APPNAMELC}
Name=%{APPNAME}Part
Name[bg]=%{APPNAME}Part
Name[bs]=%{APPNAME}Part
Name[ca]=%{APPNAME}Part
Name[ca@valencia]=%{APPNAME}Part