summaryrefslogtreecommitdiffstats
path: root/ksig
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit84da08d7b7fcda12c85caeb5a10b4903770a6f69 (patch)
tree2a6aea76f2dfffb4cc04bb907c4725af94f70e72 /ksig
downloadtdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.tar.gz
tdeaddons-84da08d7b7fcda12c85caeb5a10b4903770a6f69.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksig')
-rw-r--r--ksig/Makefile.am20
-rw-r--r--ksig/hi16-app-ksig.pngbin0 -> 751 bytes
-rw-r--r--ksig/hi32-app-ksig.pngbin0 -> 1731 bytes
-rw-r--r--ksig/ksig.cpp273
-rw-r--r--ksig/ksig.desktop72
-rw-r--r--ksig/ksig.h75
-rw-r--r--ksig/ksig.spec45
-rw-r--r--ksig/ksigui.rc26
-rw-r--r--ksig/main.cpp69
-rw-r--r--ksig/siggenerator.cpp87
-rw-r--r--ksig/siggenerator.h43
-rw-r--r--ksig/siglistview.cpp124
-rw-r--r--ksig/siglistview.h71
-rw-r--r--ksig/siglistviewitem.cpp108
-rw-r--r--ksig/siglistviewitem.h57
-rw-r--r--ksig/standardtext.cpp51
-rw-r--r--ksig/standardtext.h39
-rw-r--r--ksig/standardtextbase.ui119
18 files changed, 1279 insertions, 0 deletions
diff --git a/ksig/Makefile.am b/ksig/Makefile.am
new file mode 100644
index 0000000..733e65c
--- /dev/null
+++ b/ksig/Makefile.am
@@ -0,0 +1,20 @@
+bin_PROGRAMS = ksig
+
+ksig_SOURCES = siggenerator.cpp siglistview.cpp siglistviewitem.cpp ksig.cpp \
+ standardtextbase.ui standardtext.cpp main.cpp
+
+INCLUDES = $(all_includes)
+
+METASOURCES = AUTO
+KDE_ICON = AUTO
+
+ksig_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+ksig_LDADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KDEUI)
+
+rcdir = $(kde_datadir)/ksig
+rc_DATA = ksigui.rc
+
+xdg_apps_DATA = ksig.desktop
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp *.h -o $(podir)/ksig.pot
diff --git a/ksig/hi16-app-ksig.png b/ksig/hi16-app-ksig.png
new file mode 100644
index 0000000..1ac881b
--- /dev/null
+++ b/ksig/hi16-app-ksig.png
Binary files differ
diff --git a/ksig/hi32-app-ksig.png b/ksig/hi32-app-ksig.png
new file mode 100644
index 0000000..968d9af
--- /dev/null
+++ b/ksig/hi32-app-ksig.png
Binary files differ
diff --git a/ksig/ksig.cpp b/ksig/ksig.cpp
new file mode 100644
index 0000000..801b18c
--- /dev/null
+++ b/ksig/ksig.cpp
@@ -0,0 +1,273 @@
+/***************************************************************************
+ ksig.cpp - description
+ -------------------
+ begin : Tue Jul 9 23:14:22 EDT 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include <kapplication.h>
+#include <kstdaction.h>
+#include <kaction.h>
+#include <kconfig.h>
+#include <kglobalsettings.h>
+#include <kmessagebox.h>
+#include <kstatusbar.h>
+#include <ktextedit.h>
+#include <klistviewsearchline.h>
+#include <klocale.h>
+
+#include <qsplitter.h>
+
+#include "ksig.h"
+#include "siglistviewitem.h"
+#include "standardtext.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// public methods
+////////////////////////////////////////////////////////////////////////////////
+
+KSig::KSig(QWidget *parent, const char *name) : KMainWindow(parent, name),
+ changed(false)
+{
+ setupActions();
+ setupLayout();
+ setupSearchLine();
+
+ if (!initialGeometrySet())
+ resize(640,480);
+ setupGUI(ToolBar | Keys | StatusBar | Create);
+ setAutoSaveSettings();
+
+ readConfig();
+ loadData();
+}
+
+KSig::~KSig()
+{
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private methods
+////////////////////////////////////////////////////////////////////////////////
+
+void KSig::setupActions()
+{
+ KStdAction::openNew(this, SLOT(add()), actionCollection());
+ new KAction(i18n("Remove"), "editdelete", 0, this, SLOT(remove()), actionCollection(), "remove");
+ KStdAction::save(this, SLOT(save()), actionCollection());
+ KStdAction::quit(this, SLOT(quit()), actionCollection());
+
+ KStdAction::cut(kapp, SLOT(cut()), actionCollection());
+ KStdAction::copy(kapp, SLOT(copy()), actionCollection());
+ KStdAction::paste(kapp, SLOT(paste()), actionCollection());
+ new KAction(i18n("C&lear"), "editclear", 0, kapp, SLOT(clear()), actionCollection(), "clear");
+
+ new KAction(i18n("Edit Standard Header"), 0, 0, this, SLOT(editHeader()), actionCollection(), "editHeader");
+ new KAction(i18n("Edit Standard Footer"), 0, 0, this, SLOT(editFooter()), actionCollection(), "editFooter");
+}
+
+void KSig::setupLayout()
+{
+ splitter = new QSplitter(Qt::Vertical, this);
+
+ setCentralWidget(splitter);
+
+ sigList = SigListView::instance(splitter, "sigList");
+
+ sigEdit = new KTextEdit(splitter, "sigEdit");
+ sigEdit->setTextFormat(Qt::PlainText);
+ sigEdit->setFont(KGlobalSettings::fixedFont());
+ sigEdit->setEnabled(false);
+ sigEdit->setCheckSpellingEnabled(true);
+
+ statusBar()->insertItem(i18n(" Line: %1 ").arg(0), LineNumber, 0, true);
+ statusBar()->insertItem(i18n(" Col: %1 ").arg(0), ColumnNumber, 0, true);
+ statusBar()->show();
+
+ updateListLock = false;
+ connect(sigEdit, SIGNAL(textChanged()), this, SLOT(updateList()));
+ connect(sigList, SIGNAL(selectionChanged()), this, SLOT(updateEdit()));
+ connect(sigEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateStatus(int,int)));
+}
+
+void KSig::setupSearchLine()
+{
+ KListViewSearchLineWidget *searchWidget = new KListViewSearchLineWidget(sigList, this);
+ new KWidgetAction(searchWidget, i18n("Search"), KShortcut(), 0, 0, actionCollection(), "search");
+}
+
+void KSig::loadData()
+{
+ if(sigList->childCount() > 0) {
+ sigList->setCurrentItem(sigList->firstChild());
+ sigList->setSelected(sigList->firstChild(), true);
+
+ sigEdit->setEnabled(true);
+ }
+ else {
+ updateListLock = true;
+ sigEdit->setText(i18n("To get started, first create a new signature by selecting "
+ "\"New\" above. You will then be able to edit and save "
+ "your collection of signatures."));
+ updateListLock = false;
+ }
+ setDataChanged(false);
+}
+
+void KSig::readConfig()
+{
+ setAutoSaveSettings();
+ KConfig *config = KGlobal::config();
+ {
+ KConfigGroupSaver saver(config, "Settings");
+ if(splitter) {
+ QValueList<int> sizes;
+
+ sizes.append(config->readNumEntry("ListSize", -1));
+ sizes.append(config->readNumEntry("EditSize", -1));
+
+ if(sizes[0] > 0 && sizes[1] > 0)
+ splitter->setSizes(sizes);
+ }
+
+ header = config->readEntry("Header");
+ footer = config->readEntry("Footer");
+ }
+}
+
+void KSig::writeConfig()
+{
+ KConfig *config = KGlobal::config();
+ {
+ KConfigGroupSaver saver(config, "Settings");
+ if(splitter) {
+ QValueList<int> sizes = splitter->sizes();
+
+ config->writeEntry("ListSize", sizes[0]);
+ config->writeEntry("EditSize", sizes[1]);
+ }
+
+ config->writeEntry("Header", header);
+ config->writeEntry("Footer", footer);
+ }
+ config->sync();
+}
+
+bool KSig::queryClose()
+{
+ if(changed) {
+ int saveChanges = KMessageBox::questionYesNoCancel(this, i18n("Do you want to save your changes before exiting?"),QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
+ if(saveChanges == KMessageBox::Cancel)
+ return(false);
+ else if(saveChanges == KMessageBox::Yes)
+ save();
+ }
+
+ writeConfig();
+ return(true);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private slots
+////////////////////////////////////////////////////////////////////////////////
+
+void KSig::add()
+{
+ setDataChanged();
+ SigListViewItem *sigItem = sigList->createItem();
+ sigList->setCurrentItem(sigItem);
+
+ sigEdit->setEnabled(true);
+ sigEdit->setFocus();
+ sigEdit->clear();
+}
+
+void KSig::remove()
+{
+ setDataChanged();
+ sigEdit->clear();
+ delete(sigList->currentItem());
+}
+
+void KSig::save()
+{
+ sigList->save();
+ setDataChanged(false);
+}
+
+void KSig::setDataChanged(bool value)
+{
+ changed = value;
+
+ if(changed)
+ setCaption(kapp->makeStdCaption(QString::null, true, true));
+ else
+ setCaption(kapp->makeStdCaption(QString::null, true, false));
+}
+
+void KSig::editHeader()
+{
+ StandardText *t = new StandardText(0, 0, true);
+ t->setLabel(i18n("Standard signature header:"));
+ t->setText(header);
+
+ connect(t, SIGNAL(textUpdated(const QString &)), this, SLOT(setHeader(const QString &)));
+
+ t->exec();
+}
+
+void KSig::editFooter()
+{
+ StandardText *t = new StandardText(0, 0, true);
+ t->setLabel(i18n("Standard signature footer:"));
+ t->setText(footer);
+
+ connect(t, SIGNAL(textUpdated(const QString &)), this, SLOT(setFooter(const QString &)));
+
+ t->exec();
+}
+
+void KSig::updateList()
+{
+ if(!updateListLock) {
+ setDataChanged();
+ SigListViewItem *item = sigList->currentItem();
+ if(item)
+ item->setText(sigEdit->text());
+ }
+}
+
+void KSig::updateEdit()
+{
+ updateListLock = true;
+
+ SigListViewItem *item = sigList->currentItem();
+ if(item)
+ sigEdit->setText(item->text());
+
+ updateListLock = false;
+}
+
+void KSig::updateStatus(int line, int column)
+{
+ statusBar()->changeItem(i18n(" Line: %1 ").arg(line + 1), LineNumber);
+ statusBar()->changeItem(i18n(" Col: %1 ").arg(column + 1), ColumnNumber);
+}
+
+void KSig::quit()
+{
+ close();
+}
+
+#include "ksig.moc"
diff --git a/ksig/ksig.desktop b/ksig/ksig.desktop
new file mode 100644
index 0000000..3968ec7
--- /dev/null
+++ b/ksig/ksig.desktop
@@ -0,0 +1,72 @@
+# KDE Config File
+[Desktop Entry]
+Type=Application
+Exec=ksig -caption "%c" %i %m
+Icon=ksig
+Terminal=false
+Name=KSig
+Name[hi]=के-सिग
+Name[sv]=Ksig
+Name[tr]=Ksig
+Name[vi]=K-Ký
+GenericName=Signature Editor
+GenericName[ar]=محرر التوقيعات
+GenericName[bg]=Редактор на подписи
+GenericName[br]=Aozer ar sinadurioù
+GenericName[bs]=Editor potpisa
+GenericName[ca]=Editor per la signatura
+GenericName[cs]=Editor podpisů
+GenericName[cy]=Golygydd Llofnod
+GenericName[da]=Underskriftteditor
+GenericName[de]=Signaturen-Editor
+GenericName[el]=Επεξεργαστής υπογραφής
+GenericName[eo]=Signuma redaktilo
+GenericName[es]=Editor de firma
+GenericName[et]=Allkirja redaktor
+GenericName[eu]=Sinadura editorea
+GenericName[fa]=ویرایشگر امضا
+GenericName[fi]=Allekirjoitusmuokkain
+GenericName[fr]=Éditeur de signatures
+GenericName[fy]=Hântekeningen bewurkje
+GenericName[ga]=Eagarthóir Sínithe
+GenericName[gl]=Editor de Sinaturas
+GenericName[he]=עורך חתימות
+GenericName[hi]=हस्ताक्षर संपादक
+GenericName[hr]=Uređivač potpisa
+GenericName[hu]=Aláírásszerkesztő
+GenericName[is]=Ritill fyrir undirritanir
+GenericName[it]=Editor della firma
+GenericName[ja]=署名エディタ
+GenericName[ka]=ხელმოწერის რედაქტორი
+GenericName[kk]=Қолтаңба редакторы
+GenericName[km]=កម្មវិធី​និពន្ធ​ហត្ថលេខា
+GenericName[lt]=Parašų rengyklė
+GenericName[mk]=Уредувач на потписи
+GenericName[ms]=Editor Tandatangan
+GenericName[nb]=Signaturredigering
+GenericName[nds]=Signatuur-Editor
+GenericName[ne]=हस्ताक्षर सम्पादक
+GenericName[nl]=Handtekeningen bewerken
+GenericName[nn]=Signaturredigering
+GenericName[pa]=ਦਸਤਖਤ ਸੰਪਾਦਕ
+GenericName[pl]=Edytor podpisów
+GenericName[pt]=Editor de Assinaturas
+GenericName[pt_BR]=Editor de Assinaturas
+GenericName[ro]=Editor de semnături
+GenericName[ru]=Редактор подписей
+GenericName[sk]=Editor signatúr
+GenericName[sl]=Urejevalnik podpisov
+GenericName[sr]=Уређивач потписа
+GenericName[sr@Latn]=Uređivač potpisa
+GenericName[sv]=Signatureditor
+GenericName[ta]=கையொப்ப தொகுப்பான்
+GenericName[tg]=Муҳаррири имзоҳо
+GenericName[tr]=İmza Düzenleyici
+GenericName[uk]=Редактор підписів
+GenericName[uz]=Imzo tahrirchisi
+GenericName[uz@cyrillic]=Имзо таҳрирчиси
+GenericName[vi]=Bộ soạn thảo chữ ký
+GenericName[zh_CN]=签名编辑器
+GenericName[zh_TW]=簽名編輯器
+Categories=Qt;KDE;Utility;X-KDE-Utilities-PIM;
+DocPath=ksig/index.html
diff --git a/ksig/ksig.h b/ksig/ksig.h
new file mode 100644
index 0000000..0598f10
--- /dev/null
+++ b/ksig/ksig.h
@@ -0,0 +1,75 @@
+/***************************************************************************
+ ksig.h - description
+ -------------------
+ begin : Tue Jul 9 23:14:22 EDT 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef KSIG_H
+#define KSIG_H
+
+#include "siglistview.h"
+
+#include <kmainwindow.h>
+
+class KTextEdit;
+class QSplitter;
+
+class KSig : public KMainWindow
+{
+ Q_OBJECT
+
+public:
+ KSig(QWidget *parent = 0, const char *name = 0);
+ virtual ~KSig();
+
+private:
+ enum StatusBarColumns { LineNumber, ColumnNumber };
+
+ void setupLayout();
+ void setupActions();
+ void setupSearchLine();
+ void loadData();
+ void readConfig();
+ void writeConfig();
+
+ virtual bool queryClose();
+
+private slots:
+ void add();
+ void remove();
+ void save();
+ void quit();
+ void setDataChanged(bool value = true);
+
+ void editHeader();
+ void editFooter();
+ void setHeader(const QString &text) { header = text; writeConfig(); }
+ void setFooter(const QString &text) { footer = text; writeConfig(); }
+
+ void updateList();
+ void updateEdit();
+ void updateStatus(int line, int column);
+
+private:
+ QString header;
+ QString footer;
+
+ QSplitter *splitter;
+ SigListView *sigList;
+ KTextEdit *sigEdit;
+ bool updateListLock;
+ bool changed;
+};
+
+#endif
diff --git a/ksig/ksig.spec b/ksig/ksig.spec
new file mode 100644
index 0000000..19d77a3
--- /dev/null
+++ b/ksig/ksig.spec
@@ -0,0 +1,45 @@
+%define distversion %( perl -e '$_=\<\>;/(\\d+)\\.(\\d)\\.?(\\d)?/; print "$1$2".($3||0)' /etc/*-release)
+Name: ksmssend
+Summary: %{name} -- A frontend to smssend for KDE
+Version: 3.0.8
+Release: %{_vendor}_%{distversion}
+Copyright: GPL
+Group: X11/KDE/Utilities
+Source: ftp://ftp.kde.org/pub/kde/unstable/apps/utils/%{name}-%{version}.tar.gz
+Packager: ian reinhart geiser <[email protected]>
+BuildRoot: /tmp/%{name}-%{version}
+Prefix: `kde-config --prefix`
+
+%description
+A signature management utility. This version is compiled for %{_vendor} %{distversion}.
+
+%prep
+rm -rf $RPM_BUILD_ROOT
+%setup -n %{name}-%{version}
+WANT_AUTOCONF_2_5=1 make -f admin/Makefile.common
+CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" ./configure \
+ --disable-debug --enable-final --prefix=%{prefix} \
+ -with-install-root=$RPM_BUILD_ROOT
+
+%build
+# Setup for parallel builds
+numprocs=`egrep -c ^cpu[0-9]+ /proc/stat || :`
+if [ "$numprocs" = "0" ]; then
+ numprocs=1
+fi
+
+make -j$numprocs
+
+%install
+make prefix=$RPM_BUILD_ROOT%{prefix} install
+cd $RPM_BUILD_ROOT
+find . -type d | sed '1,2d;s,^\.,\%attr(-\,root\,root) \%dir ,' > $RPM_BUILD_DIR/%{name}-master.list
+find . -type f -o -type l | sed 's|^\.||' >> $RPM_BUILD_DIR/%{name}-master.list
+
+%clean
+#rm -rf $RPM_BUILD_ROOT
+rm -rf $RPM_BUILD_DIR/%{name}-%{version}
+rm -rf $RPM_BUILD_DIR/%{name}-master.list
+
+%files -f ../%{name}-master.list
+
diff --git a/ksig/ksigui.rc b/ksig/ksigui.rc
new file mode 100644
index 0000000..2e03b22
--- /dev/null
+++ b/ksig/ksigui.rc
@@ -0,0 +1,26 @@
+<!DOCTYPE kpartgui>
+<kpartgui name="ksig">
+
+<MenuBar>
+ <Menu name="file"><text>&amp;File</text>
+ <Action name="remove"/>
+ </Menu>
+ <Menu name="edit"><text>&amp;Edit</text>
+ <Action name="clear"/>
+ </Menu>
+ <Menu name="settings"><text>&amp;Settings</text>
+ <Action name="editHeader" append="save_merge"/>
+ <Action name="editFooter" append="save_merge"/>
+ </Menu>
+</MenuBar>
+
+<ToolBar name="mainToolBar"><text>Main Toolbar</text>
+ <Action name="remove"/>
+</ToolBar>
+
+<ToolBar name="searchToolBar" newline="true">
+ <text>Search Toolbar</text>
+ <Action name="search"/>
+</ToolBar>
+
+</kpartgui>
diff --git a/ksig/main.cpp b/ksig/main.cpp
new file mode 100644
index 0000000..0017f00
--- /dev/null
+++ b/ksig/main.cpp
@@ -0,0 +1,69 @@
+/***************************************************************************
+ main.cpp - description
+ -------------------
+ begin : Tue Jul 9 23:14:22 EDT 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include <kapplication.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+#include <kdebug.h>
+
+#include "ksig.h"
+#include "siggenerator.h"
+
+static const char description[] = I18N_NOOP("KSig");
+
+static KCmdLineOptions options[] =
+{
+ { "random", I18N_NOOP("Display a random signature"), 0},
+ { "daily", I18N_NOOP("Display a signature for the day"), 0},
+ KCmdLineLastOption
+};
+
+int main(int argc, char *argv[])
+{
+
+ KAboutData aboutData("ksig", I18N_NOOP("KSig"),
+ "1.1", description, KAboutData::License_GPL,
+ "(c) 2002, Scott Wheeler", 0, 0, "[email protected]");
+
+ aboutData.addAuthor("Scott Wheeler", 0, "[email protected]");
+ KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineArgs::addCmdLineOptions(options);
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ if(args->isSet("random") || args->isSet("daily")) {
+ KApplication a(false, false);
+ SigGenerator generator;
+
+ QTextStream output(stdout, IO_WriteOnly);
+ if(args->isSet("random"))
+ output << generator.random();
+ else if(args->isSet("daily"))
+ output << generator.daily();
+
+ return(0);
+ }
+ else {
+ KApplication a;
+
+ KSig *ksig = new KSig();
+ a.setMainWidget(ksig);
+ ksig->show();
+ return a.exec();
+ }
+}
diff --git a/ksig/siggenerator.cpp b/ksig/siggenerator.cpp
new file mode 100644
index 0000000..b232cb3
--- /dev/null
+++ b/ksig/siggenerator.cpp
@@ -0,0 +1,87 @@
+/***************************************************************************
+ siggenerator.cpp - description
+ -------------------
+ begin : Sat Jul 20 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "siggenerator.h"
+#include "siglistviewitem.h"
+
+#include <kstandarddirs.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qdatetime.h>
+
+SigGenerator::SigGenerator()
+{
+ QString dir = KGlobal::dirs()->saveLocation("appdata");
+ QFile file(dir + "sigs.sigml");
+
+ if(file.open(IO_ReadOnly) && doc.setContent(&file)) {
+ signatures = doc.elementsByTagName("signature");
+ file.close();
+ }
+
+ KConfig *config = KGlobal::config();
+ {
+ KConfigGroupSaver saver(config, "Settings");
+ header = config->readEntry("Header");
+ footer = config->readEntry("Footer");
+ }
+}
+
+SigGenerator::~SigGenerator()
+{
+
+}
+
+
+QString SigGenerator::random() const
+{
+ if(signatures.count() <= 0)
+ return(QString::null);
+
+ int i = KApplication::random() % signatures.count();
+ QString text;
+ SigListViewItem::nodeToText(signatures.item(i), text);
+
+ return attachStandard(text);
+}
+
+QString SigGenerator::daily() const
+{
+ if(signatures.count() <= 0)
+ return(QString::null);
+
+ QDate date;
+ int i = date.dayOfYear() % signatures.count();
+ QString text;
+ SigListViewItem::nodeToText(signatures.item(i), text);
+ return attachStandard(text);
+}
+
+QString SigGenerator::attachStandard(const QString &text) const
+{
+ QString s = text;
+
+ if(!header.isEmpty())
+ s = header + "\n" + s;
+ if(!footer.isEmpty())
+ s = s + "\n" + footer + "\n";
+
+ return s;
+}
diff --git a/ksig/siggenerator.h b/ksig/siggenerator.h
new file mode 100644
index 0000000..a2c429d
--- /dev/null
+++ b/ksig/siggenerator.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ siggenerator.h - description
+ -------------------
+ begin : Sat Jul 20 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef SIGGENERATOR_H
+#define SIGGENERATOR_H
+
+#include <qstring.h>
+#include <qdom.h>
+
+class SigGenerator
+{
+public:
+ SigGenerator();
+ ~SigGenerator();
+
+ QString random() const;
+ QString daily() const;
+
+private:
+
+ QString attachStandard(const QString &text) const;
+
+ QDomDocument doc;
+ QDomNodeList signatures;
+ QString header;
+ QString footer;
+};
+
+#endif
diff --git a/ksig/siglistview.cpp b/ksig/siglistview.cpp
new file mode 100644
index 0000000..d212478
--- /dev/null
+++ b/ksig/siglistview.cpp
@@ -0,0 +1,124 @@
+/***************************************************************************
+ siglistview.cpp - description
+ -------------------
+ begin : Fri Jul 19 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "siglistview.h"
+#include "siglistview.moc"
+
+#include "siglistviewitem.h"
+
+#include <kstandarddirs.h>
+#include <klocale.h>
+
+SigListView *SigListView::listView = 0;
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+SigListView *SigListView::instance(QWidget *parent, const char *name)
+{
+ if(!listView)
+ listView = new SigListView(parent, name);
+ return(listView);
+}
+
+void SigListView::load()
+{
+ if(file.open(IO_ReadOnly) && doc.setContent(&file)) {
+
+ // find the root element
+ QDomNodeList topLevelElements = doc.childNodes();
+ uint i = 0;
+ while(topLevelElements.item(i).toElement().tagName() != "SigML" && i < topLevelElements.count())
+ i++;
+
+ if(i < topLevelElements.count())
+ // if we didn't hit the end of the list
+ rootElement = topLevelElements.item(i).toElement();
+ else {
+ // if we didn't find the root element, create one
+ rootElement = doc.createElement("SigML");
+ doc.appendChild(rootElement);
+ }
+
+ QDomNodeList signatures = doc.elementsByTagName("signature");
+ for(i = 0; i < signatures.count(); i++)
+ (void) new SigListViewItem(this, doc, signatures.item(i).toElement());
+
+ file.close();
+ }
+ // if the document could not be opened or setData failed, create the document framework
+ else {
+ rootElement = doc.createElement("SigML");
+ doc.appendChild(rootElement);
+ }
+}
+
+void SigListView::save()
+{
+ QListViewItemIterator it(this);
+ while(it.current()) {
+ SigListViewItem *item = dynamic_cast<SigListViewItem *>(it.current());
+ if(item)
+ item->render();
+ it++;
+ }
+
+ if(file.open(IO_WriteOnly)) {
+ QTextStream stream(&file);
+ stream << doc;
+ file.close();
+ }
+}
+
+SigListViewItem *SigListView::createItem()
+{
+ QDomElement element = doc.createElement("signature");
+ rootElement.appendChild(element);
+
+ SigListViewItem *item = new SigListViewItem(this, doc, element);
+ return(item);
+}
+
+SigListViewItem *SigListView::currentItem()
+{
+ return(dynamic_cast<SigListViewItem *>(KListView::currentItem()));
+}
+
+const SigListViewItem *SigListView::currentItem() const
+{
+ return(dynamic_cast<SigListViewItem *>(KListView::currentItem()));
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// protected members
+////////////////////////////////////////////////////////////////////////////////
+
+SigListView::SigListView(QWidget *parent, const char *name) : KListView(parent, name)
+{
+ addColumn(i18n("Signatures"));
+
+ QString dir = KGlobal::dirs()->saveLocation("appdata");
+ if(!dir.isNull())
+ file.setName(dir + "sigs.sigml");
+ load();
+}
+
+SigListView::~SigListView()
+{
+
+}
diff --git a/ksig/siglistview.h b/ksig/siglistview.h
new file mode 100644
index 0000000..553d86c
--- /dev/null
+++ b/ksig/siglistview.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+ siglistview.h - description
+ -------------------
+ begin : Fri Jul 19 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef SIGLISTVIEW_H
+#define SIGLISTVIEW_H
+
+#include <klistview.h>
+#include <kdebug.h>
+
+#include <qfile.h>
+#include <qdom.h>
+
+class SigListViewItem;
+
+/**
+ * SigListView is implemented as a singleton, and as such has a private
+ * constructor. You can access the instance of SigListView through the
+ * instance method. This is implemented as a singleton not to provide
+ * global access, but because things will break horribly were there to
+ * be two instances of this widget created.
+*/
+
+class SigListView : public KListView
+{
+ Q_OBJECT
+public:
+ static SigListView *instance(QWidget *parent = 0, const char *name = 0);
+
+ void load();
+ void save();
+
+ /**
+ * This method should be used for all creation of SigListViewItems.
+ */
+ SigListViewItem *createItem();
+ SigListViewItem *currentItem();
+ const SigListViewItem *currentItem() const;
+
+public slots:
+ /**
+ * Override the destructive default.
+ */
+ void clear() {}
+
+protected:
+ SigListView(QWidget *parent = 0, const char *name = 0);
+ virtual ~SigListView();
+
+private:
+ static SigListView *listView;
+
+ QFile file;
+ QDomDocument doc;
+ QDomElement rootElement;
+};
+
+#endif
diff --git a/ksig/siglistviewitem.cpp b/ksig/siglistviewitem.cpp
new file mode 100644
index 0000000..6744f87
--- /dev/null
+++ b/ksig/siglistviewitem.cpp
@@ -0,0 +1,108 @@
+/***************************************************************************
+ siglistviewitem.cpp - description
+ -------------------
+ begin : Fri Jul 12 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include "siglistviewitem.h"
+
+#include <klocale.h>
+#include <kdebug.h>
+
+#include <qregexp.h>
+
+////////////////////////////////////////////////////////////////////////////////
+// public members
+////////////////////////////////////////////////////////////////////////////////
+
+SigListViewItem::~SigListViewItem()
+{
+ // remove the element from the tree
+ element.parentNode().removeChild(element);
+}
+
+QString SigListViewItem::text() const
+{
+ return(elementText);
+}
+
+void SigListViewItem::setText(const QString &t)
+{
+ if(t != elementText) {
+ elementText = t;
+ dirty = true;
+ refreshText();
+ }
+}
+
+void SigListViewItem::refreshText()
+{
+ if(!text().isEmpty())
+ KListViewItem::setText(0, text().simplifyWhiteSpace());
+ else
+ KListViewItem::setText(0, emptySigString);
+}
+
+void SigListViewItem::nodeToText(const QDomNode &n, QString &s)
+{
+ QDomNodeList children = n.childNodes();
+
+ for(uint i = 0; i < children.count(); i++) {
+ if(children.item(i).isText())
+ s.append(children.item(i).toText().data());
+ else {
+ nodeToText(children.item(i), s);
+ if(children.item(i).isElement() && children.item(i).toElement().tagName() == "p") {
+ s.append("\n");
+ }
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// private members
+////////////////////////////////////////////////////////////////////////////////
+
+SigListViewItem::SigListViewItem(QListView *parent, QDomDocument document, QDomElement signatureElement) : KListViewItem(parent)
+{
+ emptySigString = i18n("<empty signature>");
+
+ doc = document;
+ element = signatureElement;
+ nodeToText(element, elementText);
+ elementText.replace(QRegExp("\n$"), "");
+
+ dirty = false;
+ refreshText();
+}
+
+void SigListViewItem::render()
+{
+ if(dirty) {
+ QDomNodeList children = element.childNodes();
+
+ while(!element.firstChild().isNull())
+ element.removeChild(element.firstChild());
+
+ // create new children
+ QStringList lines = QStringList::split("\n", elementText, true);
+
+ for(QStringList::Iterator it = lines.begin(); it != lines.end(); it++) {
+ QDomElement p = doc.createElement("p");
+ element.appendChild(p);
+ p.appendChild(doc.createTextNode(*it));
+ }
+ dirty = false;
+ }
+}
diff --git a/ksig/siglistviewitem.h b/ksig/siglistviewitem.h
new file mode 100644
index 0000000..f3a6814
--- /dev/null
+++ b/ksig/siglistviewitem.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ siglistviewitem.h - description
+ -------------------
+ begin : Fri Jul 12 2002
+ copyright : (C) 2002 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef SIGLISTVIEWITEM_H
+#define SIGLISTVIEWITEM_H
+
+#include "siglistview.h"
+
+#include <qdom.h>
+
+class SigListViewItem : public KListViewItem
+{
+ friend class SigListView;
+public:
+ virtual ~SigListViewItem();
+ void setText(const QString &t);
+ QString text() const;
+ void refreshText();
+
+ static void nodeToText(const QDomNode &n, QString &s);
+
+private:
+ /**
+ * The constructor is private because all SigListViewItems should be
+ * created using SigListView::createItem(). This is accessible to
+ * SigListView because SigListView is a friend class.
+ */
+ SigListViewItem(QListView *parent, QDomDocument document, QDomElement signatureElement);
+
+ /**
+ * Renders the data back to the DOM element.
+ */
+ void render();
+
+ QString emptySigString;
+
+ QDomDocument doc;
+ QDomElement element;
+ QString elementText;
+ bool dirty;
+};
+
+#endif
diff --git a/ksig/standardtext.cpp b/ksig/standardtext.cpp
new file mode 100644
index 0000000..7c21e67
--- /dev/null
+++ b/ksig/standardtext.cpp
@@ -0,0 +1,51 @@
+/***************************************************************************
+ standardtext.cpp - description
+ -------------------
+ copyright : (C) 2003 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include <ktextedit.h>
+
+#include <qlabel.h>
+
+#include "standardtext.h"
+
+StandardText::StandardText(QWidget *parent, const char *name, bool modal, WFlags fl) : StandardTextBase(parent, name, modal, fl)
+{
+
+}
+
+StandardText::~StandardText()
+{
+
+}
+
+void StandardText::setLabel(const QString &text)
+{
+ label->setText(text);
+}
+
+void StandardText::setText(const QString &text)
+{
+ textEdit->setText(text);
+}
+
+void StandardText::done(int r)
+{
+ if(r == QDialog::Accepted)
+ emit textUpdated(textEdit->text());
+
+ StandardTextBase::done(r);
+}
+
+#include "standardtext.moc"
diff --git a/ksig/standardtext.h b/ksig/standardtext.h
new file mode 100644
index 0000000..dfa8b8c
--- /dev/null
+++ b/ksig/standardtext.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ standardtext.h - description
+ -------------------
+ copyright : (C) 2003 by Scott Wheeler
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#ifndef STANDARDTEXT_H
+#define STANDARDTEXT_H
+
+#include "standardtextbase.h"
+
+class StandardText : public StandardTextBase
+{
+ Q_OBJECT
+public:
+ StandardText(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags fl = 0);
+ virtual ~StandardText();
+
+ void setLabel(const QString &text);
+ void setText(const QString &text);
+
+signals:
+ void textUpdated(const QString &);
+
+private slots:
+ virtual void done(int r);
+};
+
+#endif
diff --git a/ksig/standardtextbase.ui b/ksig/standardtextbase.ui
new file mode 100644
index 0000000..d1050c2
--- /dev/null
+++ b/ksig/standardtextbase.ui
@@ -0,0 +1,119 @@
+<!DOCTYPE UI><UI version="3.1" stdsetdef="1">
+<class>StandardTextBase</class>
+<widget class="QDialog">
+ <property name="name">
+ <cstring>StandardTextBase</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>511</width>
+ <height>282</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string></string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>label</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <widget class="KTextEdit">
+ <property name="name">
+ <cstring>textEdit</cstring>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <property name="spacing">
+ <number>6</number>
+ </property>
+ <spacer>
+ <property name="name">
+ <cstring>buttonSpacer</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonOk</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;OK</string>
+ </property>
+ <property name="accel">
+ <string></string>
+ </property>
+ <property name="autoDefault">
+ <bool>true</bool>
+ </property>
+ <property name="default">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QPushButton">
+ <property name="name">
+ <cstring>buttonCancel</cstring>
+ </property>
+ <property name="text">
+ <string>&amp;Cancel</string>
+ </property>
+ <property name="accel">
+ <string></string>
+ </property>
+ <property name="autoDefault">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+</widget>
+<connections>
+ <connection>
+ <sender>buttonOk</sender>
+ <signal>clicked()</signal>
+ <receiver>StandardTextBase</receiver>
+ <slot>accept()</slot>
+ </connection>
+ <connection>
+ <sender>buttonCancel</sender>
+ <signal>clicked()</signal>
+ <receiver>StandardTextBase</receiver>
+ <slot>reject()</slot>
+ </connection>
+</connections>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>ktextedit.h</includehint>
+</includehints>
+</UI>