• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Kate

timedate.cpp

Go to the documentation of this file.
00001 
00020 #include "timedate.h"
00021 #include "timedate_config.h"
00022 
00023 #include <ktexteditor/document.h>
00024 
00025 #include <kpluginfactory.h>
00026 #include <kpluginloader.h>
00027 #include <klocale.h>
00028 #include <kaction.h>
00029 #include <kactioncollection.h>
00030 #include <kdatetime.h>
00031 #include <kconfiggroup.h>
00032 
00033 TimeDatePlugin *TimeDatePlugin::plugin = 0;
00034 
00035 K_PLUGIN_FACTORY_DEFINITION(TimeDatePluginFactory,
00036         registerPlugin<TimeDatePlugin>("ktexteditor_timedate");
00037         registerPlugin<TimeDateConfig>("ktexteditor_timedate_config");
00038         )
00039 K_EXPORT_PLUGIN(TimeDatePluginFactory("ktexteditor_timedate", "ktexteditor_plugins"))
00040 
00041 TimeDatePlugin::TimeDatePlugin(QObject *parent, const QVariantList &args)
00042     : KTextEditor::Plugin(parent)
00043 {
00044     Q_UNUSED(args);
00045 
00046     if (localizedTimeDate.isNull())
00047     {
00048         localizedTimeDate = i18nc("This is a localized string for default time & date printing on kate document."
00049                                   "%d means day in XX format."
00050                                   "%m means month in XX format."
00051                                   "%Y means year in XXXX format."
00052                                   "%H means hours in XX format."
00053                                   "%M means minutes in XX format."
00054                                   "Please, if in your language time or date is written in a different order, change it here",
00055                                   "%d-%m-%Y %H:%M");
00056     }
00057 
00058     plugin = this;
00059     readConfig();
00060 }
00061 
00062 TimeDatePlugin::~TimeDatePlugin()
00063 {
00064     plugin = 0;
00065 }
00066 
00067 void TimeDatePlugin::addView(KTextEditor::View *view)
00068 {
00069     TimeDatePluginView *nview = new TimeDatePluginView(m_string, view);
00070     m_views.append(nview);
00071 }
00072 
00073 void TimeDatePlugin::removeView(KTextEditor::View *view)
00074 {
00075     for (int z = 0; z < m_views.size(); z++)
00076     {
00077         if (m_views.at(z)->parentClient() == view)
00078         {
00079             TimeDatePluginView *nview = m_views.at(z);
00080             m_views.removeAll(nview);
00081             delete nview;
00082         }
00083     }
00084 }
00085 
00086 void TimeDatePlugin::readConfig()
00087 {
00088     KConfigGroup cg(KGlobal::config(), "TimeDate Plugin");
00089     m_string = cg.readEntry("string", localizedTimeDate);
00090 }
00091 
00092 void TimeDatePlugin::writeConfig()
00093 {
00094     KConfigGroup cg(KGlobal::config(), "TimeDate Plugin" );
00095     cg.writeEntry("string", m_string );
00096 }
00097 
00098 void TimeDatePlugin::setFormat(const QString &format)
00099 {
00100     m_string = format;
00101 
00102     // If the property has been set for the plugin in general, let's set that
00103     // property to that value on all views where the plugin has been loaded.
00104     foreach (TimeDatePluginView *pluginView, m_views)
00105     {
00106         pluginView->setFormat(format);
00107     }
00108 }
00109 
00110 QString TimeDatePlugin::format() const
00111 {
00112     return m_string;
00113 }
00114 
00115 TimeDatePluginView::TimeDatePluginView(const QString &string,
00116                                        KTextEditor::View *view)
00117   : QObject(view)
00118   , KXMLGUIClient(view)
00119   , m_view(view)
00120   , m_string(string)
00121 {
00122     setComponentData(TimeDatePluginFactory::componentData());
00123 
00124     KAction *action = new KAction(i18n("Insert Time && Date"), this);
00125     actionCollection()->addAction("tools_insert_timedate", action);
00126     action->setShortcut(Qt::CTRL + Qt::Key_D);
00127     connect(action, SIGNAL(triggered()), this, SLOT(slotInsertTimeDate()));
00128 
00129     setXMLFile("timedateui.rc");
00130 }
00131 
00132 TimeDatePluginView::~TimeDatePluginView()
00133 {
00134 }
00135 
00136 void TimeDatePluginView::setFormat(const QString &format)
00137 {
00138     m_string = format;
00139 }
00140 
00141 QString TimeDatePluginView::format() const
00142 {
00143     return m_string;
00144 }
00145 
00146 void TimeDatePluginView::slotInsertTimeDate()
00147 {
00148     KDateTime dt(QDateTime::currentDateTime());
00149     m_view->document()->insertText(m_view->cursorPosition(), dt.toString(m_string));
00150 }
00151 
00152 #include "timedate.moc"

Kate

Skip menu "Kate"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal