• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knotes

  • sources
  • kde-4.12
  • kdepim
  • knotes
  • utils
knoteutils.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "knoteutils.h"
19 #include "knoteconfig.h"
20 #include "network/knotehostdialog.h"
21 #include "network/knotesnetsend.h"
22 #include "kdepim-version.h"
23 #include "knotes/knotesglobalconfig.h"
24 
25 #include <KCal/Journal>
26 using namespace KCal;
27 
28 #include <KIO/NetAccess>
29 #include <KSharedConfig>
30 #include <KStandardDirs>
31 #include <KProcess>
32 #include <KMessageBox>
33 #include <KLocale>
34 #include <ksocketfactory.h>
35 
36 #include <QPointer>
37 
38 KNoteConfig *KNoteUtils::createConfig(KCal::Journal *journal, QString &configPath)
39 {
40  // the config file location
41  configPath = KGlobal::dirs()->saveLocation( "data", QLatin1String("knotes/") ) + QLatin1String("notes/") + journal->uid();
42 
43  // no config file yet? -> use the default display config if available
44  // we want to write to configFile, so use "false"
45  const bool newNote = !KIO::NetAccess::exists( KUrl( configPath ), KIO::NetAccess::DestinationSide, 0 );
46 
47  KNoteConfig *config = new KNoteConfig( KSharedConfig::openConfig( configPath, KConfig::NoGlobals ) );
48  config->readConfig();
49  config->setVersion( QLatin1String(KDEPIM_VERSION) );
50 
51  if ( newNote ) {
52  // until kdelibs provides copying of KConfigSkeletons (KDE 3.4)
53  KNotesGlobalConfig *globalConfig = KNotesGlobalConfig::self();
54  config->setBgColor( globalConfig->bgColor() );
55  config->setFgColor( globalConfig->fgColor() );
56  config->setWidth( globalConfig->width() );
57  config->setHeight( globalConfig->height() );
58 
59  config->setFont( globalConfig->font() );
60  config->setTitleFont( globalConfig->titleFont() );
61  config->setAutoIndent( globalConfig->autoIndent() );
62  config->setRichText( globalConfig->richText() );
63  config->setTabSize( globalConfig->tabSize() );
64  config->setReadOnly( globalConfig->readOnly() );
65 
66  config->setDesktop( globalConfig->desktop() );
67  config->setHideNote( globalConfig->hideNote() );
68  config->setPosition( globalConfig->position() );
69  config->setShowInTaskbar( globalConfig->showInTaskbar() );
70  config->setRememberDesktop( globalConfig->rememberDesktop() );
71  config->setKeepAbove( globalConfig->keepAbove() );
72  config->setKeepBelow( globalConfig->keepBelow() );
73 
74  config->writeConfig();
75  }
76  return config;
77 }
78 
79 
80 void KNoteUtils::setProperty(KCal::Journal *journal, KNoteConfig *config)
81 {
82  // config items in the journal have priority
83  QString property = journal->customProperty( "KNotes", "FgColor" );
84  if ( !property.isNull() ) {
85  config->setFgColor( QColor( property ) );
86  } else {
87  journal->setCustomProperty( "KNotes", "FgColor",
88  config->fgColor().name() );
89  }
90 
91  property = journal->customProperty( "KNotes", "BgColor" );
92  if ( !property.isNull() ) {
93  config->setBgColor( QColor( property ) );
94  } else {
95  journal->setCustomProperty( "KNotes", "BgColor",
96  config->bgColor().name() );
97  }
98  property = journal->customProperty( "KNotes", "RichText" );
99  if ( !property.isNull() ) {
100  config->setRichText( property == QLatin1String("true") ? true : false );
101  } else {
102  journal->setCustomProperty( "KNotes", "RichText",
103  config->richText() ? QLatin1String("true") : QLatin1String("false") );
104  }
105 }
106 
107 
108 void KNoteUtils::removeNote(KCal::Journal *journal, QWidget *parent)
109 {
110  const QString configFile = KGlobal::dirs()->saveLocation( "data", QLatin1String("knotes/") ) + QLatin1String("notes/") + journal->uid();
111  if ( !KIO::NetAccess::del( KUrl( configFile ), parent ) ) {
112  qDebug() <<"Can't remove the note config:" << configFile;
113  }
114 
115 }
116 
117 void KNoteUtils::savePreferences( KCal::Journal *journal, KNoteConfig *config)
118 {
119  journal->setCustomProperty( "KNotes", "FgColor",
120  config->fgColor().name() );
121  journal->setCustomProperty( "KNotes", "BgColor",
122  config->bgColor().name() );
123  journal->setCustomProperty( "KNotes", "RichText",
124  config->richText() ? QLatin1String("true") : QLatin1String("false") );
125 }
126 
127 
128 void KNoteUtils::sendMail(QWidget *parent, const QString &title, const QString &message)
129 {
130  // get the mail action command
131  const QStringList cmd_list = KNotesGlobalConfig::mailAction().split( QLatin1Char(' '), QString::SkipEmptyParts );
132  if (cmd_list.isEmpty()) {
133  KMessageBox::sorry( parent, i18n( "Please configure send mail action." ) );
134  return;
135  }
136  KProcess mail;
137  foreach ( const QString &cmd, cmd_list ) {
138  if ( cmd == QLatin1String("%f") ) {
139  mail << message;
140  } else if ( cmd == QLatin1String("%t") ) {
141  mail << title;
142  } else {
143  mail << cmd;
144  }
145  }
146 
147  if ( !mail.startDetached() ) {
148  KMessageBox::sorry( parent, i18n( "Unable to start the mail process." ) );
149  }
150 }
151 
152 
153 void KNoteUtils::sendToNetwork(QWidget *parent, const QString &title, const QString &message)
154 {
155  // pop up dialog to get the IP
156  QPointer<KNoteHostDialog> hostDlg = new KNoteHostDialog( i18n( "Send \"%1\"", title ), parent );
157  if ( hostDlg->exec() ) {
158 
159  const QString host = hostDlg->host();
160  quint16 port = hostDlg->port();
161 
162  if ( !port ) { // not specified, use default
163  port = KNotesGlobalConfig::port();
164  }
165 
166  if ( host.isEmpty() ) {
167  KMessageBox::sorry( parent, i18n( "The host cannot be empty." ) );
168  delete hostDlg;
169  return;
170  }
171 
172  // Send the note
173 
174  KNotesNetworkSender *sender = new KNotesNetworkSender(
175  KSocketFactory::connectToHost( QLatin1String("knotes"), host, port ) );
176  sender->setSenderId( KNotesGlobalConfig::senderID() );
177  sender->setNote( title, message ); // FIXME: plainText ??
178  }
179  delete hostDlg;
180 }
181 
knotesnetsend.h
knotehostdialog.h
KNoteConfig::setKeepAbove
void setKeepAbove(bool v)
Set KeepAbove.
Definition: knoteconfig.h:295
KNoteConfig::setBgColor
void setBgColor(const QColor &v)
Set bgcolor.
Definition: knoteconfig.h:23
KNoteConfig
Definition: knoteconfig.h:13
KNotesNetworkSender
Definition: knotesnetsend.h:39
QWidget
KNoteConfig::setShowInTaskbar
void setShowInTaskbar(bool v)
Set ShowInTaskbar.
Definition: knoteconfig.h:278
KNoteConfig::setRememberDesktop
void setRememberDesktop(bool v)
Set RememberDesktop.
Definition: knoteconfig.h:91
KNoteConfig::setTabSize
void setTabSize(uint v)
Set tabsize.
Definition: knoteconfig.h:176
KNoteConfig::setReadOnly
void setReadOnly(bool v)
Set ReadOnly.
Definition: knoteconfig.h:193
KNoteHostDialog
A dialog that allows to select network service or request a hostname or IP address.
Definition: knotehostdialog.h:46
KNoteConfig::bgColor
QColor bgColor() const
Get bgcolor.
Definition: knoteconfig.h:32
KNoteUtils::createConfig
KNOTES_EXPORT KNoteConfig * createConfig(KCal::Journal *journal, QString &configPath)
Definition: knoteutils.cpp:38
KNoteConfig::setPosition
void setPosition(const QPoint &v)
Set position.
Definition: knoteconfig.h:261
KNoteConfig::setVersion
void setVersion(const QString &v)
Set version.
Definition: knoteconfig.h:210
KNoteConfig::setHideNote
void setHideNote(bool v)
Set HideNote.
Definition: knoteconfig.h:244
KNoteConfig::setRichText
void setRichText(bool v)
Set richtext.
Definition: knoteconfig.h:159
knoteutils.h
KNoteUtils::setProperty
KNOTES_EXPORT void setProperty(KCal::Journal *journal, KNoteConfig *config)
Definition: knoteutils.cpp:80
KNoteConfig::setAutoIndent
void setAutoIndent(bool v)
Set autoindent.
Definition: knoteconfig.h:142
KNoteUtils::removeNote
KNOTES_EXPORT void removeNote(KCal::Journal *journal, QWidget *parent)
Definition: knoteutils.cpp:108
KNoteConfig::fgColor
QColor fgColor() const
Get fgcolor.
Definition: knoteconfig.h:49
KNoteConfig::setHeight
void setHeight(uint v)
Set height.
Definition: knoteconfig.h:74
KNoteConfig::setFont
void setFont(const QFont &v)
Set font.
Definition: knoteconfig.h:108
KNoteConfig::richText
bool richText() const
Get richtext.
Definition: knoteconfig.h:168
KNotesNetworkSender::setNote
void setNote(const QString &title, const QString &text)
Definition: knotesnetsend.cpp:64
KNoteConfig::setDesktop
void setDesktop(int v)
Set desktop.
Definition: knoteconfig.h:227
KNoteUtils::savePreferences
KNOTES_EXPORT void savePreferences(KCal::Journal *journal, KNoteConfig *config)
Definition: knoteutils.cpp:117
KNoteConfig::setFgColor
void setFgColor(const QColor &v)
Set fgcolor.
Definition: knoteconfig.h:40
knoteconfig.h
KNoteConfig::setWidth
void setWidth(uint v)
Set width.
Definition: knoteconfig.h:57
KNoteConfig::setTitleFont
void setTitleFont(const QFont &v)
Set titlefont.
Definition: knoteconfig.h:125
KNoteUtils::sendMail
KNOTES_EXPORT void sendMail(QWidget *parent, const QString &title, const QString &message)
Definition: knoteutils.cpp:128
KNoteConfig::setKeepBelow
void setKeepBelow(bool v)
Set KeepBelow.
Definition: knoteconfig.h:312
KNotesNetworkSender::setSenderId
void setSenderId(const QString &sender)
Definition: knotesnetsend.cpp:58
KNoteUtils::sendToNetwork
KNOTES_EXPORT void sendToNetwork(QWidget *parent, const QString &title, const QString &message)
Definition: knoteutils.cpp:153
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal