[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: New Feature (sort of): new DCOP method for KNotes
From:       Michael Brade <brade () kde ! org>
Date:       2006-06-10 20:51:46
Message-ID: 200606102251.52297.brade () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


On Saturday 10 June 2006 21:42, Michael Brade wrote:
> I'm not 100% happy with the patch, since I wrote it yesterday to be as
> small as possible for review but setColor() shouldn't be public in it's
> current state. I'll come up with the final patch to test for Cornelius in a
> bit.
Ok, here we go, final patch. It is now even possible to change the color and 
kill KNotes immediately afterwards without loosing data. Extensively tested, 
found to be bullet-proof ;-)

But the testing lead me to a little bug in libkcal: 
KCal::Journal::setCustomProperty() doesn't call updated(), thus even a call 
to save() doesn't actually write the data to disk. 

For now I called updated() manually in setColor(), which should be the only 
place that is needed in KNotes, but I wonder if there are other apps that 
also loose their custom properties if nothing else was changed?

Cornelius, please test and tell me if it's ok to commit :-)

Cheers,
-- 
Rohan (Michael) Brade;         KDE Developer, Student of Computer Science
  |-mail: echo brade !#|tr -d "c oh"|s\e\d 's/e/\@/2;s/$/.org/;s/bra/k/2'
  °--web: http://www.kde.org/people/michaelb.html

KDE 4: Beyond Your Expectations

["PATCH.dcop-color" (text/x-diff)]

Index: KNotesIface.h
===================================================================
--- KNotesIface.h	(revision 536898)
+++ KNotesIface.h	(working copy)
@@ -86,6 +86,29 @@
     virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0;
 
     /**
+     * Returns the foreground/text color of a note.
+     * @param noteId the id of the note in question
+     * @return the foreground/text color as a QString
+     */
+    virtual QString fgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Returns the background color of a note.
+     * @param noteId the id of the note in question
+     * @return the background color as a QString
+     */
+    virtual QString bgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Sets the color (foreground and background color) of a note.
+     * @param noteId the id of the note
+     * @param fgColor the new text color for the note
+     * @param bgColor the new background color for the note
+     */
+    virtual ASYNC setColor( const QString& noteId, const QString& fgColor,
+                                                   const QString& bgColor ) = 0;
+
+    /**
      * Returns the title/name of a note.
      * @param noteId the id of the note in question
      * @return the name as a QString
Index: KNotesAppIface.h
===================================================================
--- KNotesAppIface.h	(revision 536898)
+++ KNotesAppIface.h	(working copy)
@@ -96,6 +96,29 @@
     virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0;
 
     /**
+     * Returns the foreground/text color of a note.
+     * @param noteId the id of the note in question
+     * @return the foreground/text color as a QString
+     */
+    virtual QString fgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Returns the background color of a note.
+     * @param noteId the id of the note in question
+     * @return the background color as a QString
+     */
+    virtual QString bgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Sets the color (foreground and background color) of a note.
+     * @param noteId the id of the note
+     * @param fgColor the new text color for the note
+     * @param bgColor the new background color for the note
+     */
+    virtual ASYNC setColor( const QString& noteId, const QString& fgColor,
+                                                   const QString& bgColor ) = 0;
+
+    /**
      * Returns the title/name of a note.
      * @param noteId the id of the note in question
      * @return the name as a QString
Index: knotesapp.h
===================================================================
--- knotesapp.h	(revision 536898)
+++ knotesapp.h	(working copy)
@@ -72,6 +72,12 @@
     void setName( const QString& id, const QString& newName );
     void setText( const QString& id, const QString& newText );
 
+    QString fgColor( const QString& id ) const;
+    QString bgColor( const QString& id ) const;
+
+    void setColor( const QString& id, const QString& fgColor,
+                                      const QString& bgColor );
+
     QMap<QString,QString> notes() const;
 
     void sync( const QString& app );
Index: knote.cpp
===================================================================
--- knote.cpp	(revision 550047)
+++ knote.cpp	(working copy)
@@ -486,9 +486,15 @@
 
 void KNote::setColor( const QColor& fg, const QColor& bg )
 {
+    m_journal->setCustomProperty( "KNotes", "FgColor", fg.name() );
+    m_journal->setCustomProperty( "KNotes", "BgColor", bg.name() );
     m_config->setFgColor( fg );
     m_config->setBgColor( bg );
 
+    m_journal->updated();  // because setCustomProperty() doesn't call it!!
+    emit sigDataChanged();
+    saveConfig();
+
     QPalette newpalette = palette();
     newpalette.setColor( QColorGroup::Background, bg );
     newpalette.setColor( QColorGroup::Foreground, fg );
@@ -1256,11 +1262,7 @@
 
     QColor bg;
     if ( KColorDrag::decode( e, bg ) )
-    {
         setColor( paletteForegroundColor(), bg );
-        m_journal->setCustomProperty( "KNotes", "BgColor", bg.name() );
-        m_config->setBgColor( bg );
-    }
 }
 
 bool KNote::focusNextPrevChild( bool )
Index: knotesapp.cpp
===================================================================
--- knotesapp.cpp	(revision 536898)
+++ knotesapp.cpp	(working copy)
@@ -355,6 +355,33 @@
         kdWarning(5500) << "setText: no note with id: " << id << endl;
 }
 
+QString KNotesApp::fgColor( const QString& id ) const
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        return note->fgColor().name();
+    else
+        return QString::null;
+}
+
+QString KNotesApp::bgColor( const QString& id ) const
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        return note->bgColor().name();
+    else
+        return QString::null;
+}
+
+void KNotesApp::setColor( const QString& id, const QString& fgColor, const QString& bgColor )
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        note->setColor( QColor( fgColor ), QColor( bgColor ) );
+    else
+        kdWarning(5500) << "setColor: no note with id: " << id << endl;
+}
+
 void KNotesApp::sync( const QString& app )
 {
     QDictIterator<KNote> it( m_noteList );

[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic