aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2014-01-23 11:29:36 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2014-01-23 11:29:36 (GMT)
commit8bb2c6d3ebadb6018ee109ba75263d9d667f3bbf (patch)
tree09466f1b54bb0907685137b153e8563658001aa5
parent08010e22c0fc5e685e869e95463daa4130192dfd (diff)
kdelibs coding style, like ktexteditor, astyle-kdelibs for the win
-rw-r--r--kwrite/kwrite.cpp537
-rw-r--r--kwrite/kwrite.h76
-rw-r--r--kwrite/main.cpp403
3 files changed, 508 insertions, 508 deletions
diff --git a/kwrite/kwrite.cpp b/kwrite/kwrite.cpp
index 36f394d..022e317 100644
--- a/kwrite/kwrite.cpp
+++ b/kwrite/kwrite.cpp
@@ -55,10 +55,10 @@
#include <QLabel>
#include <QDragEnterEvent>
-QList<KTextEditor::Document*> KWrite::docList;
-QList<KWrite*> KWrite::winList;
+QList<KTextEditor::Document *> KWrite::docList;
+QList<KWrite *> KWrite::winList;
-KWrite::KWrite (KTextEditor::Document *doc)
+KWrite::KWrite(KTextEditor::Document *doc)
: m_view(0),
m_recentFiles(0),
m_paShowPath(0),
@@ -67,122 +67,122 @@ KWrite::KWrite (KTextEditor::Document *doc)
, m_activityResource(0)
#endif
{
- if ( !doc )
- {
- doc = KTextEditor::Editor::instance()->createDocument(0);
+ if (!doc) {
+ doc = KTextEditor::Editor::instance()->createDocument(0);
- // enable the modified on disk warning dialogs if any
- if (qobject_cast<KTextEditor::ModificationInterface *>(doc))
- qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning (true);
+ // enable the modified on disk warning dialogs if any
+ if (qobject_cast<KTextEditor::ModificationInterface *>(doc)) {
+ qobject_cast<KTextEditor::ModificationInterface *>(doc)->setModifiedOnDiskWarning(true);
+ }
- docList.append(doc);
- }
+ docList.append(doc);
+ }
- m_view = doc->createView (this);
+ m_view = doc->createView(this);
- setCentralWidget(m_view);
+ setCentralWidget(m_view);
- setupActions();
+ setupActions();
- // signals for the statusbar
- connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
- connect(m_view->document(), SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
- connect(m_view->document(), SIGNAL(readWriteChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
- connect(m_view->document(),SIGNAL(documentUrlChanged(KTextEditor::Document*)), this, SLOT(urlChanged()));
+ // signals for the statusbar
+ connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
+ connect(m_view->document(), SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
+ connect(m_view->document(), SIGNAL(readWriteChanged(KTextEditor::Document*)), this, SLOT(documentNameChanged()));
+ connect(m_view->document(), SIGNAL(documentUrlChanged(KTextEditor::Document*)), this, SLOT(urlChanged()));
- setAcceptDrops(true);
- connect(m_view,SIGNAL(dropEventPass(QDropEvent*)),this,SLOT(slotDropEvent(QDropEvent*)));
+ setAcceptDrops(true);
+ connect(m_view, SIGNAL(dropEventPass(QDropEvent*)), this, SLOT(slotDropEvent(QDropEvent*)));
- setXMLFile(QStringLiteral("kwriteui.rc"));
- createShellGUI( true );
- guiFactory()->addClient( m_view );
+ setXMLFile(QStringLiteral("kwriteui.rc"));
+ createShellGUI(true);
+ guiFactory()->addClient(m_view);
- // init with more useful size, stolen from konq :)
-/* FIXME KF5 if (!initialGeometrySet())
- resize( QSize(700, 480).expandedTo(minimumSizeHint()));
-*/
+ // init with more useful size, stolen from konq :)
+ /* FIXME KF5 if (!initialGeometrySet())
+ resize( QSize(700, 480).expandedTo(minimumSizeHint()));
+ */
- // FIXME: make sure the config dir exists, any idea how to do it more cleanly?
- QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).mkpath(QStringLiteral("."));
+ // FIXME: make sure the config dir exists, any idea how to do it more cleanly?
+ QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)).mkpath(QStringLiteral("."));
- // call it as last thing, must be sure everything is already set up ;)
- setAutoSaveSettings ();
+ // call it as last thing, must be sure everything is already set up ;)
+ setAutoSaveSettings();
- readConfig ();
+ readConfig();
- winList.append (this);
+ winList.append(this);
- documentNameChanged ();
- show ();
+ documentNameChanged();
+ show();
- // give view focus
- m_view->setFocus (Qt::OtherFocusReason);
+ // give view focus
+ m_view->setFocus(Qt::OtherFocusReason);
}
KWrite::~KWrite()
{
- guiFactory()->removeClient(m_view);
+ guiFactory()->removeClient(m_view);
- winList.removeAll(this);
-
- KTextEditor::Document *doc = m_view->document();
- delete m_view;
+ winList.removeAll(this);
- // kill document, if last view is closed
- if (doc->views().isEmpty()) {
- docList.removeAll(doc);
- delete doc;
- }
+ KTextEditor::Document *doc = m_view->document();
+ delete m_view;
- KSharedConfig::openConfig()->sync();
+ // kill document, if last view is closed
+ if (doc->views().isEmpty()) {
+ docList.removeAll(doc);
+ delete doc;
+ }
+
+ KSharedConfig::openConfig()->sync();
}
void KWrite::setupActions()
{
- actionCollection()->addAction( KStandardAction::Close, QStringLiteral("file_close"), this, SLOT(slotFlush()) )
+ actionCollection()->addAction(KStandardAction::Close, QStringLiteral("file_close"), this, SLOT(slotFlush()))
->setWhatsThis(i18n("Use this command to close the current document"));
- // setup File menu
- actionCollection()->addAction( KStandardAction::New, QStringLiteral("file_new"), this, SLOT(slotNew()) )
+ // setup File menu
+ actionCollection()->addAction(KStandardAction::New, QStringLiteral("file_new"), this, SLOT(slotNew()))
->setWhatsThis(i18n("Use this command to create a new document"));
- actionCollection()->addAction( KStandardAction::Open, QStringLiteral("file_open"), this, SLOT(slotOpen()) )
+ actionCollection()->addAction(KStandardAction::Open, QStringLiteral("file_open"), this, SLOT(slotOpen()))
->setWhatsThis(i18n("Use this command to open an existing document for editing"));
- m_recentFiles = KStandardAction::openRecent(this, SLOT(slotOpen(QUrl)), this);
- actionCollection()->addAction(m_recentFiles->objectName(), m_recentFiles);
- m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
+ m_recentFiles = KStandardAction::openRecent(this, SLOT(slotOpen(QUrl)), this);
+ actionCollection()->addAction(m_recentFiles->objectName(), m_recentFiles);
+ m_recentFiles->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
- QAction *a = actionCollection()->addAction( QStringLiteral("view_new_view") );
- a->setIcon( QIcon::fromTheme(QStringLiteral("window-new")) );
- a->setText( i18n("&New Window") );
- connect( a, SIGNAL(triggered()), this, SLOT(newView()) );
- a->setWhatsThis(i18n("Create another view containing the current document"));
+ QAction *a = actionCollection()->addAction(QStringLiteral("view_new_view"));
+ a->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
+ a->setText(i18n("&New Window"));
+ connect(a, SIGNAL(triggered()), this, SLOT(newView()));
+ a->setWhatsThis(i18n("Create another view containing the current document"));
- actionCollection()->addAction( KStandardAction::Quit, this, SLOT(close()) )
+ actionCollection()->addAction(KStandardAction::Quit, this, SLOT(close()))
->setWhatsThis(i18n("Close the current document view"));
- // setup Settings menu
- setStandardToolBarMenuEnabled(true);
+ // setup Settings menu
+ setStandardToolBarMenuEnabled(true);
- m_paShowStatusBar = KStandardAction::showStatusbar(this, SLOT(toggleStatusBar()), this);
- actionCollection()->addAction( m_paShowStatusBar->objectName(), m_paShowStatusBar);
- m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
+ m_paShowStatusBar = KStandardAction::showStatusbar(this, SLOT(toggleStatusBar()), this);
+ actionCollection()->addAction(m_paShowStatusBar->objectName(), m_paShowStatusBar);
+ m_paShowStatusBar->setWhatsThis(i18n("Use this command to show or hide the view's statusbar"));
- m_paShowPath = new KToggleAction( i18n("Sho&w Path"), this );
- actionCollection()->addAction( QStringLiteral("set_showPath"), m_paShowPath );
- connect( m_paShowPath, SIGNAL(triggered()), this, SLOT(documentNameChanged()) );
- m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
+ m_paShowPath = new KToggleAction(i18n("Sho&w Path"), this);
+ actionCollection()->addAction(QStringLiteral("set_showPath"), m_paShowPath);
+ connect(m_paShowPath, SIGNAL(triggered()), this, SLOT(documentNameChanged()));
+ m_paShowPath->setWhatsThis(i18n("Show the complete document path in the window caption"));
- a= actionCollection()->addAction( KStandardAction::KeyBindings, this, SLOT(editKeys()) );
- a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
+ a = actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(editKeys()));
+ a->setWhatsThis(i18n("Configure the application's keyboard shortcut assignments."));
- a = actionCollection()->addAction( KStandardAction::ConfigureToolbars, QStringLiteral("options_configure_toolbars"),
- this, SLOT(editToolbars()) );
- a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
+ a = actionCollection()->addAction(KStandardAction::ConfigureToolbars, QStringLiteral("options_configure_toolbars"),
+ this, SLOT(editToolbars()));
+ a->setWhatsThis(i18n("Configure which items should appear in the toolbar(s)."));
- a = actionCollection()->addAction( QStringLiteral("help_about_editor") );
- a->setText( i18n("&About Editor Component") );
- connect( a, SIGNAL(triggered()), this, SLOT(aboutEditor()) );
+ a = actionCollection()->addAction(QStringLiteral("help_about_editor"));
+ a->setText(i18n("&About Editor Component"));
+ connect(a, SIGNAL(triggered()), this, SLOT(aboutEditor()));
}
@@ -190,318 +190,319 @@ void KWrite::setupActions()
void KWrite::loadURL(const QUrl &url)
{
#ifdef KActivities_FOUND
- if (!m_activityResource) {
- m_activityResource = new KActivities::ResourceInstance(winId(), this);
- }
- m_activityResource->setUri(url);
+ if (!m_activityResource) {
+ m_activityResource = new KActivities::ResourceInstance(winId(), this);
+ }
+ m_activityResource->setUri(url);
#endif
- m_view->document()->openUrl(url);
+ m_view->document()->openUrl(url);
}
// is closing the window wanted by user ?
bool KWrite::queryClose()
{
- if (m_view->document()->views().count() > 1)
- return true;
+ if (m_view->document()->views().count() > 1) {
+ return true;
+ }
- if (m_view->document()->queryClose())
- {
- writeConfig();
+ if (m_view->document()->queryClose()) {
+ writeConfig();
- return true;
- }
+ return true;
+ }
- return false;
+ return false;
}
-void KWrite::slotFlush ()
+void KWrite::slotFlush()
{
- m_view->document()->closeUrl();
+ m_view->document()->closeUrl();
}
void KWrite::slotNew()
{
- new KWrite();
+ new KWrite();
}
void KWrite::slotOpen()
{
- const KEncodingFileDialog::Result r=KEncodingFileDialog::getOpenUrlsAndEncoding(KTextEditor::Editor::instance()->defaultEncoding(), m_view->document()->url(),QString(),this,i18n("Open File"));
- Q_FOREACH (QUrl url, r.URLs) {
- encoding = r.encoding;
- slotOpen ( url );
- }
+ const KEncodingFileDialog::Result r = KEncodingFileDialog::getOpenUrlsAndEncoding(KTextEditor::Editor::instance()->defaultEncoding(), m_view->document()->url(), QString(), this, i18n("Open File"));
+ Q_FOREACH(QUrl url, r.URLs) {
+ encoding = r.encoding;
+ slotOpen(url);
+ }
}
-void KWrite::slotOpen( const QUrl& url )
+void KWrite::slotOpen(const QUrl &url)
{
- if (url.isEmpty()) return;
-
- KIO::StatJob *job = KIO::stat(url, KIO::StatJob::SourceSide, 0);
- KJobWidgets::setWindow(job, this);
- if (!job->exec())
- {
- KMessageBox::error (this, i18n("The file given could not be read; check whether it exists or is readable for the current user."));
- return;
- }
-
- if (m_view->document()->isModified() || !m_view->document()->url().isEmpty())
- {
- KWrite *t = new KWrite();
- t->m_view->document()->setEncoding(encoding);
- t->loadURL(url);
- }
- else
- {
- m_view->document()->setEncoding(encoding);
- loadURL(url);
- }
+ if (url.isEmpty()) {
+ return;
+ }
+
+ KIO::StatJob *job = KIO::stat(url, KIO::StatJob::SourceSide, 0);
+ KJobWidgets::setWindow(job, this);
+ if (!job->exec()) {
+ KMessageBox::error(this, i18n("The file given could not be read; check whether it exists or is readable for the current user."));
+ return;
+ }
+
+ if (m_view->document()->isModified() || !m_view->document()->url().isEmpty()) {
+ KWrite *t = new KWrite();
+ t->m_view->document()->setEncoding(encoding);
+ t->loadURL(url);
+ } else {
+ m_view->document()->setEncoding(encoding);
+ loadURL(url);
+ }
}
void KWrite::urlChanged()
{
- if ( ! m_view->document()->url().isEmpty() )
- m_recentFiles->addUrl( m_view->document()->url() );
-
- // update caption
- documentNameChanged ();
+ if (! m_view->document()->url().isEmpty()) {
+ m_recentFiles->addUrl(m_view->document()->url());
+ }
+
+ // update caption
+ documentNameChanged();
}
void KWrite::newView()
{
- new KWrite(m_view->document());
+ new KWrite(m_view->document());
}
void KWrite::toggleStatusBar()
{
- m_view->setStatusBarEnabled(m_paShowStatusBar->isChecked());
+ m_view->setStatusBarEnabled(m_paShowStatusBar->isChecked());
}
void KWrite::editKeys()
{
- KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
- dlg.addCollection(actionCollection());
- if( m_view )
- dlg.addCollection(m_view->actionCollection());
- dlg.configure();
+ KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
+ dlg.addCollection(actionCollection());
+ if (m_view) {
+ dlg.addCollection(m_view->actionCollection());
+ }
+ dlg.configure();
}
void KWrite::editToolbars()
{
- KConfigGroup cfg = KSharedConfig::openConfig()->group( "MainWindow" );
- saveMainWindowSettings(cfg);
- KEditToolBar dlg(guiFactory(), this);
+ KConfigGroup cfg = KSharedConfig::openConfig()->group("MainWindow");
+ saveMainWindowSettings(cfg);
+ KEditToolBar dlg(guiFactory(), this);
- connect( &dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()) );
- dlg.exec();
+ connect(&dlg, SIGNAL(newToolBarConfig()), this, SLOT(slotNewToolbarConfig()));
+ dlg.exec();
}
void KWrite::slotNewToolbarConfig()
{
- applyMainWindowSettings( KSharedConfig::openConfig()->group( "MainWindow" ) );
+ applyMainWindowSettings(KSharedConfig::openConfig()->group("MainWindow"));
}
-void KWrite::dragEnterEvent( QDragEnterEvent *event )
+void KWrite::dragEnterEvent(QDragEnterEvent *event)
{
- const QList<QUrl> uriList = event->mimeData()->urls();
- event->setAccepted( ! uriList.isEmpty());
+ const QList<QUrl> uriList = event->mimeData()->urls();
+ event->setAccepted(! uriList.isEmpty());
}
-void KWrite::dropEvent( QDropEvent *event )
+void KWrite::dropEvent(QDropEvent *event)
{
- slotDropEvent(event);
+ slotDropEvent(event);
}
-void KWrite::slotDropEvent( QDropEvent *event )
+void KWrite::slotDropEvent(QDropEvent *event)
{
- const QList<QUrl> textlist = event->mimeData()->urls();
+ const QList<QUrl> textlist = event->mimeData()->urls();
- foreach (const QUrl & url, textlist)
- slotOpen (url);
+ foreach(const QUrl & url, textlist)
+ slotOpen(url);
}
-void KWrite::slotEnableActions( bool enable )
+void KWrite::slotEnableActions(bool enable)
{
- QList<QAction *> actions = actionCollection()->actions();
- QList<QAction *>::ConstIterator it = actions.constBegin();
- QList<QAction *>::ConstIterator end = actions.constEnd();
+ QList<QAction *> actions = actionCollection()->actions();
+ QList<QAction *>::ConstIterator it = actions.constBegin();
+ QList<QAction *>::ConstIterator end = actions.constEnd();
- for (; it != end; ++it )
- (*it)->setEnabled( enable );
+ for (; it != end; ++it) {
+ (*it)->setEnabled(enable);
+ }
- actions = m_view->actionCollection()->actions();
- it = actions.constBegin();
- end = actions.constEnd();
+ actions = m_view->actionCollection()->actions();
+ it = actions.constBegin();
+ end = actions.constEnd();
- for (; it != end; ++it )
- (*it)->setEnabled( enable );
+ for (; it != end; ++it) {
+ (*it)->setEnabled(enable);
+ }
}
//common config
void KWrite::readConfig(KSharedConfigPtr config)
{
- KConfigGroup cfg( config, "General Options");
+ KConfigGroup cfg(config, "General Options");
- m_paShowStatusBar->setChecked( cfg.readEntry("ShowStatusBar", true) );
- m_paShowPath->setChecked( cfg.readEntry("ShowPath", false) );
+ m_paShowStatusBar->setChecked(cfg.readEntry("ShowStatusBar", true));
+ m_paShowPath->setChecked(cfg.readEntry("ShowPath", false));
- m_recentFiles->loadEntries( config->group( "Recent Files" ));
+ m_recentFiles->loadEntries(config->group("Recent Files"));
- // editor config already read from KSharedConfig::openConfig() in KWriteApp constructor.
- // so only load, if the config is a different one (this is only the case on
- // session restore)
- if (config != KSharedConfig::openConfig())
- KTextEditor::Editor::instance()->readConfig(config.data());
+ // editor config already read from KSharedConfig::openConfig() in KWriteApp constructor.
+ // so only load, if the config is a different one (this is only the case on
+ // session restore)
+ if (config != KSharedConfig::openConfig()) {
+ KTextEditor::Editor::instance()->readConfig(config.data());
+ }
- m_view->setStatusBarEnabled(m_paShowStatusBar->isChecked());
+ m_view->setStatusBarEnabled(m_paShowStatusBar->isChecked());
}
void KWrite::writeConfig(KSharedConfigPtr config)
{
- KConfigGroup generalOptions( config, "General Options");
+ KConfigGroup generalOptions(config, "General Options");
- generalOptions.writeEntry("ShowStatusBar",m_paShowStatusBar->isChecked());
- generalOptions.writeEntry("ShowPath",m_paShowPath->isChecked());
+ generalOptions.writeEntry("ShowStatusBar", m_paShowStatusBar->isChecked());
+ generalOptions.writeEntry("ShowPath", m_paShowPath->isChecked());
- m_recentFiles->saveEntries(KConfigGroup(config, "Recent Files"));
+ m_recentFiles->saveEntries(KConfigGroup(config, "Recent Files"));
- // Writes into its own group
- KTextEditor::Editor::instance()->writeConfig(config.data());
+ // Writes into its own group
+ KTextEditor::Editor::instance()->writeConfig(config.data());
- config->sync ();
+ config->sync();
}
//config file
void KWrite::readConfig()
{
- readConfig(KSharedConfig::openConfig());
+ readConfig(KSharedConfig::openConfig());
}
void KWrite::writeConfig()
{
- writeConfig(KSharedConfig::openConfig());
+ writeConfig(KSharedConfig::openConfig());
}
// session management
void KWrite::restore(KConfig *config, int n)
{
- readPropertiesInternal(config, n);
+ readPropertiesInternal(config, n);
}
void KWrite::readProperties(const KConfigGroup &config)
{
- readConfig();
+ readConfig();
- if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view))
- iface->readSessionConfig(KConfigGroup(&config, QStringLiteral("General Options")));
+ if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view)) {
+ iface->readSessionConfig(KConfigGroup(&config, QStringLiteral("General Options")));
+ }
}
void KWrite::saveProperties(KConfigGroup &config)
{
- writeConfig();
+ writeConfig();
- config.writeEntry("DocumentNumber",docList.indexOf(m_view->document()) + 1);
+ config.writeEntry("DocumentNumber", docList.indexOf(m_view->document()) + 1);
- if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view)) {
- KConfigGroup cg(&config, QStringLiteral("General Options"));
- iface->writeSessionConfig(cg);
- }
+ if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(m_view)) {
+ KConfigGroup cg(&config, QStringLiteral("General Options"));
+ iface->writeSessionConfig(cg);
+ }
}
void KWrite::saveGlobalProperties(KConfig *config) //save documents
{
- config->group("Number").writeEntry("NumberOfDocuments",docList.count());
-
- for (int z = 1; z <= docList.count(); z++)
- {
- QString buf = QString::fromLatin1("Document %1").arg(z);
- KConfigGroup cg( config, buf );
- KTextEditor::Document *doc = docList.at(z - 1);
-
- if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc))
- iface->writeSessionConfig(cg);
- }
-
- for (int z = 1; z <= winList.count(); z++)
- {
- QString buf = QString::fromLatin1("Window %1").arg(z);
- KConfigGroup cg( config, buf );
- cg.writeEntry("DocumentNumber",docList.indexOf(winList.at(z-1)->view()->document()) + 1);
- }
+ config->group("Number").writeEntry("NumberOfDocuments", docList.count());
+
+ for (int z = 1; z <= docList.count(); z++) {
+ QString buf = QString::fromLatin1("Document %1").arg(z);
+ KConfigGroup cg(config, buf);
+ KTextEditor::Document *doc = docList.at(z - 1);
+
+ if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc)) {
+ iface->writeSessionConfig(cg);
+ }
+ }
+
+ for (int z = 1; z <= winList.count(); z++) {
+ QString buf = QString::fromLatin1("Window %1").arg(z);
+ KConfigGroup cg(config, buf);
+ cg.writeEntry("DocumentNumber", docList.indexOf(winList.at(z - 1)->view()->document()) + 1);
+ }
}
//restore session
void KWrite::restore()
{
- KConfig *config = KConfigGui::sessionConfig();
-
- if (!config)
- return;
-
- int docs, windows;
- QString buf;
- KTextEditor::Document *doc;
- KWrite *t;
-
- KConfigGroup numberConfig(config, "Number");
- docs = numberConfig.readEntry("NumberOfDocuments", 0);
- windows = numberConfig.readEntry("NumberOfWindows", 0);
-
- for (int z = 1; z <= docs; z++)
- {
- buf = QString::fromLatin1("Document %1").arg(z);
- KConfigGroup cg(config, buf);
- doc=KTextEditor::Editor::instance()->createDocument(0);
-
- if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc))
- iface->readSessionConfig(cg);
- docList.append(doc);
- }
-
- for (int z = 1; z <= windows; z++)
- {
- buf = QString::fromLatin1("Window %1").arg(z);
- KConfigGroup cg(config, buf);
- t = new KWrite(docList.at(cg.readEntry("DocumentNumber", 0) - 1));
- t->restore(config,z);
- }
+ KConfig *config = KConfigGui::sessionConfig();
+
+ if (!config) {
+ return;
+ }
+
+ int docs, windows;
+ QString buf;
+ KTextEditor::Document *doc;
+ KWrite *t;
+
+ KConfigGroup numberConfig(config, "Number");
+ docs = numberConfig.readEntry("NumberOfDocuments", 0);
+ windows = numberConfig.readEntry("NumberOfWindows", 0);
+
+ for (int z = 1; z <= docs; z++) {
+ buf = QString::fromLatin1("Document %1").arg(z);
+ KConfigGroup cg(config, buf);
+ doc = KTextEditor::Editor::instance()->createDocument(0);
+
+ if (KTextEditor::SessionConfigInterface *iface = qobject_cast<KTextEditor::SessionConfigInterface *>(doc)) {
+ iface->readSessionConfig(cg);
+ }
+ docList.append(doc);
+ }
+
+ for (int z = 1; z <= windows; z++) {
+ buf = QString::fromLatin1("Window %1").arg(z);
+ KConfigGroup cg(config, buf);
+ t = new KWrite(docList.at(cg.readEntry("DocumentNumber", 0) - 1));
+ t->restore(config, z);
+ }
}
void KWrite::aboutEditor()
{
- KAboutApplicationDialog dlg(KTextEditor::Editor::instance()->aboutData(), this);
- dlg.exec();
+ KAboutApplicationDialog dlg(KTextEditor::Editor::instance()->aboutData(), this);
+ dlg.exec();
}
-void KWrite::documentNameChanged ()
+void KWrite::documentNameChanged()
{
- QString readOnlyCaption;
- if (!m_view->document()->isReadWrite())
- readOnlyCaption=i18n(" [read only]");
-
- if (m_view->document()->url().isEmpty()) {
- setCaption(i18n("Untitled")+readOnlyCaption+QStringLiteral(" [*]"),m_view->document()->isModified());
- }
- else
- {
- QString c;
- if (!m_paShowPath->isChecked())
- {
- c = m_view->document()->url().fileName();
-
- //File name shouldn't be too long - Maciek
- if (c.length() > 64)
- c = c.left(64) + QStringLiteral("...");
+ QString readOnlyCaption;
+ if (!m_view->document()->isReadWrite()) {
+ readOnlyCaption = i18n(" [read only]");
}
- else
- {
- c = m_view->document()->url().toString();
- //File name shouldn't be too long - Maciek
- if (c.length() > 64)
- c = QStringLiteral("...") + c.right(64);
+ if (m_view->document()->url().isEmpty()) {
+ setCaption(i18n("Untitled") + readOnlyCaption + QStringLiteral(" [*]"), m_view->document()->isModified());
+ } else {
+ QString c;
+ if (!m_paShowPath->isChecked()) {
+ c = m_view->document()->url().fileName();
+
+ //File name shouldn't be too long - Maciek
+ if (c.length() > 64) {
+ c = c.left(64) + QStringLiteral("...");
+ }
+ } else {
+ c = m_view->document()->url().toString();
+
+ //File name shouldn't be too long - Maciek
+ if (c.length() > 64) {
+ c = QStringLiteral("...") + c.right(64);
+ }
+ }
+
+ setCaption(c + readOnlyCaption, m_view->document()->isModified());
}
-
- setCaption (c+readOnlyCaption, m_view->document()->isModified());
- }
}
diff --git a/kwrite/kwrite.h b/kwrite/kwrite.h
index 6898aab..b1072a9 100644
--- a/kwrite/kwrite.h
+++ b/kwrite/kwrite.h
@@ -33,7 +33,10 @@
class QLabel;
#ifdef KActivities_FOUND
-namespace KActivities { class ResourceInstance; }
+namespace KActivities
+{
+class ResourceInstance;
+}
#endif
class KToggleAction;
@@ -42,88 +45,91 @@ class KSqueezedTextLabel;
class KWrite : public KParts::MainWindow
{
- Q_OBJECT
+ Q_OBJECT
- public:
+public:
KWrite(KTextEditor::Document * = 0L);
~KWrite();
void loadURL(const QUrl &url);
- KTextEditor::View *view() const { return m_view; }
+ KTextEditor::View *view() const {
+ return m_view;
+ }
- static bool noWindows () { return winList.isEmpty(); }
+ static bool noWindows() {
+ return winList.isEmpty();
+ }
- private:
+private:
void setupActions();
bool queryClose();
- void dragEnterEvent( QDragEnterEvent * );
- void dropEvent( QDropEvent * );
+ void dragEnterEvent(QDragEnterEvent *);
+ void dropEvent(QDropEvent *);
- public Q_SLOTS:
+public Q_SLOTS:
void slotNew();
- void slotFlush ();
+ void slotFlush();
void slotOpen();
- void slotOpen( const QUrl& url);
+ void slotOpen(const QUrl &url);
void newView();
void toggleStatusBar();
void editKeys();
void editToolbars();
void aboutEditor();
- private Q_SLOTS:
+private Q_SLOTS:
void slotNewToolbarConfig();
- public Q_SLOTS:
+public Q_SLOTS:
void slotDropEvent(QDropEvent *);
- void slotEnableActions( bool enable );
+ void slotEnableActions(bool enable);
/**
* adds a changed URL to the recent files
*/
void urlChanged();
- //config file functions
- public:
- void readConfig (KSharedConfigPtr);
- void writeConfig (KSharedConfigPtr);
+ //config file functions
+public:
+ void readConfig(KSharedConfigPtr);
+ void writeConfig(KSharedConfigPtr);
- void readConfig ();
- void writeConfig ();
+ void readConfig();
+ void writeConfig();
- //session management
- public:
- void restore(KConfig *,int);
+ //session management
+public:
+ void restore(KConfig *, int);
static void restore();
- private:
+private:
void readProperties(const KConfigGroup &);
void saveProperties(KConfigGroup &);
void saveGlobalProperties(KConfig *);
- private:
- KTextEditor::View * m_view;
+private:
+ KTextEditor::View *m_view;
- KRecentFilesAction * m_recentFiles;
- KToggleAction * m_paShowPath;
- KToggleAction * m_paShowStatusBar;
+ KRecentFilesAction *m_recentFiles;
+ KToggleAction *m_paShowPath;
+ KToggleAction *m_paShowStatusBar;
#ifdef KActivities_FOUND
- KActivities::ResourceInstance * m_activityResource;
+ KActivities::ResourceInstance *m_activityResource;
#endif
QString encoding;
- static QList<KTextEditor::Document*> docList;
- static QList<KWrite*> winList;
+ static QList<KTextEditor::Document *> docList;
+ static QList<KWrite *> winList;
- public Q_SLOTS:
- void documentNameChanged ();
+public Q_SLOTS:
+ void documentNameChanged();
};
#endif
-// kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off;
diff --git a/kwrite/main.cpp b/kwrite/main.cpp
index 1b22eb4..fdb8f88 100644
--- a/kwrite/main.cpp
+++ b/kwrite/main.cpp
@@ -37,224 +37,217 @@
extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
{
- /**
- * first init the app
- */
- QApplication app (argc, argv);
-
- /**
- * then use i18n and co
- */
- KAboutData aboutData ( QStringLiteral("kwrite"), QString(),
+ /**
+ * first init the app
+ */
+ QApplication app(argc, argv);
+
+ /**
+ * then use i18n and co
+ */
+ KAboutData aboutData(QStringLiteral("kwrite"), QString(),
i18n("KWrite"),
QStringLiteral(KATE_VERSION),
- i18n( "KWrite - Text Editor" ), KAboutData::License_LGPL_V2,
- i18n( "(c) 2000-2014 The Kate Authors" ), QString(), QStringLiteral("http://kate-editor.org") );
-
- /**
- * right dbus prefix == org.kde.
- */
- aboutData.setOrganizationDomain (QByteArray("kde.org"));
-
- aboutData.addAuthor (i18n("Christoph Cullmann"), i18n("Maintainer"), QStringLiteral("cullmann@kde.org"), QStringLiteral("http://www.cullmann.io"));
- aboutData.addAuthor (i18n("Anders Lund"), i18n("Core Developer"), QStringLiteral("anders@alweb.dk"), QStringLiteral("http://www.alweb.dk"));
- aboutData.addAuthor (i18n("Joseph Wenninger"), i18n("Core Developer"), QStringLiteral("jowenn@kde.org"), QStringLiteral("http://stud3.tuwien.ac.at/~e9925371"));
- aboutData.addAuthor (i18n("Hamish Rodda"),i18n("Core Developer"), QStringLiteral("rodda@kde.org"));
- aboutData.addAuthor (i18n("Dominik Haumann"), i18n("Developer & Highlight wizard"), QStringLiteral("dhdev@gmx.de"));
- aboutData.addAuthor (i18n("Waldo Bastian"), i18n("The cool buffersystem"), QStringLiteral("bastian@kde.org") );
- aboutData.addAuthor (i18n("Charles Samuels"), i18n("The Editing Commands"), QStringLiteral("charles@kde.org"));
- aboutData.addAuthor (i18n("Matt Newell"), i18nc("Credit text for someone that did testing and some other similar things", "Testing, ..."), QStringLiteral("newellm@proaxis.com"));
- aboutData.addAuthor (i18n("Michael Bartl"), i18n("Former Core Developer"), QStringLiteral("michael.bartl1@chello.at"));
- aboutData.addAuthor (i18n("Michael McCallum"), i18n("Core Developer"), QStringLiteral("gholam@xtra.co.nz"));
- aboutData.addAuthor (i18n("Jochen Wilhemly"), i18n("KWrite Author"), QStringLiteral("digisnap@cs.tu-berlin.de") );
- aboutData.addAuthor (i18n("Michael Koch"),i18n("KWrite port to KParts"), QStringLiteral("koch@kde.org"));
- aboutData.addAuthor (i18n("Christian Gebauer"), QString(), QStringLiteral("gebauer@kde.org") );
- aboutData.addAuthor (i18n("Simon Hausmann"), QString(), QStringLiteral("hausmann@kde.org") );
- aboutData.addAuthor (i18n("Glen Parker"),i18n("KWrite Undo History, Kspell integration"), QStringLiteral("glenebob@nwlink.com"));
- aboutData.addAuthor (i18n("Scott Manson"),i18n("KWrite XML Syntax highlighting support"), QStringLiteral("sdmanson@alltel.net"));
- aboutData.addAuthor (i18n("John Firebaugh"),i18n("Patches and more"), QStringLiteral("jfirebaugh@kde.org"));
- aboutData.addAuthor (i18n("Gerald Senarclens de Grancy"), i18n("QA and Scripting"), QStringLiteral("oss@senarclens.eu"), QStringLiteral("http://find-santa.eu/"));
-
- aboutData.addCredit (i18n("Matteo Merli"),i18n("Highlighting for RPM Spec-Files, Perl, Diff and more"), QStringLiteral("merlim@libero.it"));
- aboutData.addCredit (i18n("Rocky Scaletta"),i18n("Highlighting for VHDL"), QStringLiteral("rocky@purdue.edu"));
- aboutData.addCredit (i18n("Yury Lebedev"),i18n("Highlighting for SQL"));
- aboutData.addCredit (i18n("Chris Ross"),i18n("Highlighting for Ferite"));
- aboutData.addCredit (i18n("Nick Roux"),i18n("Highlighting for ILERPG"));
- aboutData.addCredit (i18n("Carsten Niehaus"), i18n("Highlighting for LaTeX"));
- aboutData.addCredit (i18n("Per Wigren"), i18n("Highlighting for Makefiles, Python"));
- aboutData.addCredit (i18n("Jan Fritz"), i18n("Highlighting for Python"));
- aboutData.addCredit (i18n("Daniel Naber"));
- aboutData.addCredit (i18n("Roland Pabel"),i18n("Highlighting for Scheme"));
- aboutData.addCredit (i18n("Cristi Dumitrescu"),i18n("PHP Keyword/Datatype list"));
- aboutData.addCredit (i18n("Carsten Pfeiffer"), i18nc("Credit text for someone that helped a lot", "Very nice help"));
- aboutData.addCredit (i18n("All people who have contributed and I have forgotten to mention"));
-
- aboutData.setProgramIconName (QStringLiteral("accessories-text-editor"));
- aboutData.setProductName(QByteArray("kate/kwrite"));
-
- /**
- * register about data
- */
- KAboutData::setApplicationData (aboutData);
-
- /**
- * set app stuff from about data component name and org. name from KAboutData
- */
- app.setApplicationName (aboutData.componentName());
- app.setApplicationDisplayName (aboutData.displayName());
- app.setOrganizationDomain (aboutData.organizationDomain());
- app.setApplicationVersion (aboutData.version());
-
- /**
- * Create command line parser and feed it with known options
- */
- QCommandLineParser parser;
- aboutData.setupCommandLine (&parser);
- parser.setApplicationDescription(aboutData.shortDescription());
- parser.addHelpOption();
- parser.addVersionOption();
-
- // -e/--encoding option
- const QCommandLineOption useEncoding (QStringList () << QStringLiteral("e") << QStringLiteral("encoding"), i18n("Set encoding for the file to open."), QStringLiteral("encoding"));
- parser.addOption (useEncoding);
-
- // -l/--line option
- const QCommandLineOption gotoLine (QStringList () << QStringLiteral("l") << QStringLiteral("line"), i18n("Navigate to this line."), QStringLiteral("line"));
- parser.addOption (gotoLine);
-
- // -c/--column option
- const QCommandLineOption gotoColumn (QStringList () << QStringLiteral("c") << QStringLiteral("column"), i18n("Navigate to this column."), QStringLiteral("column"));
- parser.addOption (gotoColumn);
-
- // -i/--stdin option
- const QCommandLineOption readStdIn (QStringList () << QStringLiteral("i") << QStringLiteral("stdin"), i18n("Read the contents of stdin."));
- parser.addOption (readStdIn);
-
- // --tempfile option
- const QCommandLineOption tempfile (QStringList () << QStringLiteral("tempfile"), i18n("The files/URLs opened by the application will be deleted after use"));
- parser.addOption (tempfile);
-
- // urls to open
- parser.addPositionalArgument(QStringLiteral("urls"), i18n("Documents to open."), QStringLiteral("[urls...]"));
-
- /**
- * do the command line parsing
- */
- parser.process (app);
-
- /**
- * handle standard options
- */
- aboutData.processCommandLine (&parser);
-
- // read from global config once
- KTextEditor::Editor::instance()->readConfig(KSharedConfig::openConfig().data());
-
- if ( app.isSessionRestored() )
- {
- KWrite::restore();
- }
- else
- {
- bool nav = false;
- int line = 0, column = 0;
-
- QTextCodec *codec = parser.isSet(QStringLiteral("encoding")) ? QTextCodec::codecForName(parser.value(QStringLiteral("encoding")).toLocal8Bit()) : 0;
-
- if (parser.isSet (QStringLiteral("line")))
- {
- line = parser.value (QStringLiteral("line")).toInt() - 1;
- nav = true;
- }
-
- if (parser.isSet (QStringLiteral("column")))
- {
- column = parser.value (QStringLiteral("column")).toInt() - 1;
- nav = true;
- }
+ i18n("KWrite - Text Editor"), KAboutData::License_LGPL_V2,
+ i18n("(c) 2000-2014 The Kate Authors"), QString(), QStringLiteral("http://kate-editor.org"));
+
+ /**
+ * right dbus prefix == org.kde.
+ */
+ aboutData.setOrganizationDomain(QByteArray("kde.org"));
+
+ aboutData.addAuthor(i18n("Christoph Cullmann"), i18n("Maintainer"), QStringLiteral("cullmann@kde.org"), QStringLiteral("http://www.cullmann.io"));
+ aboutData.addAuthor(i18n("Anders Lund"), i18n("Core Developer"), QStringLiteral("anders@alweb.dk"), QStringLiteral("http://www.alweb.dk"));
+ aboutData.addAuthor(i18n("Joseph Wenninger"), i18n("Core Developer"), QStringLiteral("jowenn@kde.org"), QStringLiteral("http://stud3.tuwien.ac.at/~e9925371"));
+ aboutData.addAuthor(i18n("Hamish Rodda"), i18n("Core Developer"), QStringLiteral("rodda@kde.org"));
+ aboutData.addAuthor(i18n("Dominik Haumann"), i18n("Developer & Highlight wizard"), QStringLiteral("dhdev@gmx.de"));
+ aboutData.addAuthor(i18n("Waldo Bastian"), i18n("The cool buffersystem"), QStringLiteral("bastian@kde.org"));
+ aboutData.addAuthor(i18n("Charles Samuels"), i18n("The Editing Commands"), QStringLiteral("charles@kde.org"));
+ aboutData.addAuthor(i18n("Matt Newell"), i18nc("Credit text for someone that did testing and some other similar things", "Testing, ..."), QStringLiteral("newellm@proaxis.com"));
+ aboutData.addAuthor(i18n("Michael Bartl"), i18n("Former Core Developer"), QStringLiteral("michael.bartl1@chello.at"));
+ aboutData.addAuthor(i18n("Michael McCallum"), i18n("Core Developer"), QStringLiteral("gholam@xtra.co.nz"));
+ aboutData.addAuthor(i18n("Jochen Wilhemly"), i18n("KWrite Author"), QStringLiteral("digisnap@cs.tu-berlin.de"));
+ aboutData.addAuthor(i18n("Michael Koch"), i18n("KWrite port to KParts"), QStringLiteral("koch@kde.org"));
+ aboutData.addAuthor(i18n("Christian Gebauer"), QString(), QStringLiteral("gebauer@kde.org"));
+ aboutData.addAuthor(i18n("Simon Hausmann"), QString(), QStringLiteral("hausmann@kde.org"));
+ aboutData.addAuthor(i18n("Glen Parker"), i18n("KWrite Undo History, Kspell integration"), QStringLiteral("glenebob@nwlink.com"));
+ aboutData.addAuthor(i18n("Scott Manson"), i18n("KWrite XML Syntax highlighting support"), QStringLiteral("sdmanson@alltel.net"));
+ aboutData.addAuthor(i18n("John Firebaugh"), i18n("Patches and more"), QStringLiteral("jfirebaugh@kde.org"));
+ aboutData.addAuthor(i18n("Gerald Senarclens de Grancy"), i18n("QA and Scripting"), QStringLiteral("oss@senarclens.eu"), QStringLiteral("http://find-santa.eu/"));
+
+ aboutData.addCredit(i18n("Matteo Merli"), i18n("Highlighting for RPM Spec-Files, Perl, Diff and more"), QStringLiteral("merlim@libero.it"));
+ aboutData.addCredit(i18n("Rocky Scaletta"), i18n("Highlighting for VHDL"), QStringLiteral("rocky@purdue.edu"));
+ aboutData.addCredit(i18n("Yury Lebedev"), i18n("Highlighting for SQL"));
+ aboutData.addCredit(i18n("Chris Ross"), i18n("Highlighting for Ferite"));
+ aboutData.addCredit(i18n("Nick Roux"), i18n("Highlighting for ILERPG"));
+ aboutData.addCredit(i18n("Carsten Niehaus"), i18n("Highlighting for LaTeX"));
+ aboutData.addCredit(i18n("Per Wigren"), i18n("Highlighting for Makefiles, Python"));
+ aboutData.addCredit(i18n("Jan Fritz"), i18n("Highlighting for Python"));
+ aboutData.addCredit(i18n("Daniel Naber"));
+ aboutData.addCredit(i18n("Roland Pabel"), i18n("Highlighting for Scheme"));
+ aboutData.addCredit(i18n("Cristi Dumitrescu"), i18n("PHP Keyword/Datatype list"));
+ aboutData.addCredit(i18n("Carsten Pfeiffer"), i18nc("Credit text for someone that helped a lot", "Very nice help"));
+ aboutData.addCredit(i18n("All people who have contributed and I have forgotten to mention"));
+
+ aboutData.setProgramIconName(QStringLiteral("accessories-text-editor"));
+ aboutData.setProductName(QByteArray("kate/kwrite"));
+
+ /**
+ * register about data
+ */
+ KAboutData::setApplicationData(aboutData);
+
+ /**
+ * set app stuff from about data component name and org. name from KAboutData
+ */
+ app.setApplicationName(aboutData.componentName());
+ app.setApplicationDisplayName(aboutData.displayName());
+ app.setOrganizationDomain(aboutData.organizationDomain());
+ app.setApplicationVersion(aboutData.version());
+
+ /**
+ * Create command line parser and feed it with known options
+ */
+ QCommandLineParser parser;
+ aboutData.setupCommandLine(&parser);
+ parser.setApplicationDescription(aboutData.shortDescription());
+ parser.addHelpOption();
+ parser.addVersionOption();
+
+ // -e/--encoding option
+ const QCommandLineOption useEncoding(QStringList() << QStringLiteral("e") << QStringLiteral("encoding"), i18n("Set encoding for the file to open."), QStringLiteral("encoding"));
+ parser.addOption(useEncoding);
+
+ // -l/--line option
+ const QCommandLineOption gotoLine(QStringList() << QStringLiteral("l") << QStringLiteral("line"), i18n("Navigate to this line."), QStringLiteral("line"));
+ parser.addOption(gotoLine);
+
+ // -c/--column option
+ const QCommandLineOption gotoColumn(QStringList() << QStringLiteral("c") << QStringLiteral("column"), i18n("Navigate to this column."), QStringLiteral("column"));
+ parser.addOption(gotoColumn);
+
+ // -i/--stdin option
+ const QCommandLineOption readStdIn(QStringList() << QStringLiteral("i") << QStringLiteral("stdin"), i18n("Read the contents of stdin."));
+ parser.addOption(readStdIn);
+
+ // --tempfile option
+ const QCommandLineOption tempfile(QStringList() << QStringLiteral("tempfile"), i18n("The files/URLs opened by the application will be deleted after use"));
+ parser.addOption(tempfile);
+
+ // urls to open
+ parser.addPositionalArgument(QStringLiteral("urls"), i18n("Documents to open."), QStringLiteral("[urls...]"));
+
+ /**
+ * do the command line parsing
+ */
+ parser.process(app);
+
+ /**
+ * handle standard options
+ */
+ aboutData.processCommandLine(&parser);
+
+ // read from global config once
+ KTextEditor::Editor::instance()->readConfig(KSharedConfig::openConfig().data());
+
+ if (app.isSessionRestored()) {
+ KWrite::restore();
+ } else {
+ bool nav = false;
+ int line = 0, column = 0;
+
+ QTextCodec *codec = parser.isSet(QStringLiteral("encoding")) ? QTextCodec::codecForName(parser.value(QStringLiteral("encoding")).toLocal8Bit()) : 0;
+
+ if (parser.isSet(QStringLiteral("line"))) {
+ line = parser.value(QStringLiteral("line")).toInt() - 1;
+ nav = true;
+ }
- if ( parser.positionalArguments().count() == 0 )
- {
- KWrite *t = new KWrite;
+ if (parser.isSet(QStringLiteral("column"))) {
+ column = parser.value(QStringLiteral("column")).toInt() - 1;
+ nav = true;
+ }
- if( parser.isSet( QStringLiteral("stdin") ) )
- {
- QTextStream input(stdin, QIODevice::ReadOnly);
+ if (parser.positionalArguments().count() == 0) {
+ KWrite *t = new KWrite;
- // set chosen codec
- if (codec)
- input.setCodec (codec);
+ if (parser.isSet(QStringLiteral("stdin"))) {
+ QTextStream input(stdin, QIODevice::ReadOnly);
- QString line;
- QString text;
+ // set chosen codec
+ if (codec) {
+ input.setCodec(codec);
+ }
- do
- {
- line = input.readLine();
- text.append( line + QLatin1Char('\n') );
- } while( !line.isNull() );
+ QString line;
+ QString text;
+ do {
+ line = input.readLine();
+ text.append(line + QLatin1Char('\n'));
+ } while (!line.isNull());
- KTextEditor::Document *doc = t->view()->document();
- if( doc )
- doc->setText( text );
- }
+ KTextEditor::Document *doc = t->view()->document();
+ if (doc) {
+ doc->setText(text);
+ }
+ }
- if (nav && t->view())
- t->view()->setCursorPosition (KTextEditor::Cursor (line, column));
- }
- else
- {
- int docs_opened = 0;
- Q_FOREACH (const QString positionalArgument, parser.positionalArguments())
- {
- QUrl url;
-
- // convert to an url
- QRegExp withProtocol(QStringLiteral("^[a-zA-Z]+:")); // TODO: remove after Qt supports this on its own
- if (withProtocol.indexIn(positionalArgument) == 0) {
- url = QUrl::fromUserInput(positionalArgument);
+ if (nav && t->view()) {
+ t->view()->setCursorPosition(KTextEditor::Cursor(line, column));
+ }
} else {
- url = QUrl::fromLocalFile(positionalArgument);
+ int docs_opened = 0;
+ Q_FOREACH(const QString positionalArgument, parser.positionalArguments()) {
+ QUrl url;
+
+ // convert to an url
+ QRegExp withProtocol(QStringLiteral("^[a-zA-Z]+:")); // TODO: remove after Qt supports this on its own
+ if (withProtocol.indexIn(positionalArgument) == 0) {
+ url = QUrl::fromUserInput(positionalArgument);
+ } else {
+ url = QUrl::fromLocalFile(positionalArgument);
+ }
+
+ // this file is no local dir, open it, else warn
+ bool noDir = !url.isLocalFile() || !QFileInfo(url.toLocalFile()).isDir();
+
+ if (noDir) {
+ ++docs_opened;
+ KWrite *t = new KWrite();
+
+ if (codec) {
+ t->view()->document()->setEncoding(QString::fromLatin1(codec->name()));
+ }
+
+ t->loadURL(url);
+
+ if (nav) {
+ t->view()->setCursorPosition(KTextEditor::Cursor(line, column));
+ }
+ } else {
+ KMessageBox::sorry(0, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", url.toString()));
+ }
+ }
+ if (!docs_opened) {
+ ::exit(1); // see http://bugs.kde.org/show_bug.cgi?id=124708
+ }
}
+ }
- // this file is no local dir, open it, else warn
- bool noDir = !url.isLocalFile() || !QFileInfo (url.toLocalFile()).isDir();
-
- if (noDir)
- {
- ++docs_opened;
- KWrite *t = new KWrite();
-
- if (codec)
- t->view()->document()->setEncoding(QString::fromLatin1(codec->name()));
+ // no window there, uh, ohh, for example borked session config !!!
+ // create at least one !!
+ if (KWrite::noWindows()) {
+ new KWrite();
+ }
- t->loadURL( url );
+ /**
+ * finally register this kwrite instance for dbus
+ */
+ const KDBusService dbusService(KDBusService::Multiple);
- if (nav)
- t->view()->setCursorPosition (KTextEditor::Cursor (line, column));
- }
- else
- {
- KMessageBox::sorry(0, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", url.toString()));
- }
- }
- if (!docs_opened) ::exit(1); // see http://bugs.kde.org/show_bug.cgi?id=124708
- }
- }
-
- // no window there, uh, ohh, for example borked session config !!!
- // create at least one !!
- if (KWrite::noWindows())
- new KWrite();
-
- /**
- * finally register this kwrite instance for dbus
- */
- const KDBusService dbusService (KDBusService::Multiple);
-
- /**
- * Run the event loop
- */
- return app.exec ();
+ /**
+ * Run the event loop
+ */
+ return app.exec();
}