Starting from version 4.x, KDesktop, Kicker and SuperKaramba in KDE have come to Plasma Desktop, which have been replaced with proven over the years but obsolete (of course, opinions can also be divided). This framework represents the desktop (at least its visible part) as a collection of widgets or plasmoids. Having acquired a certain amount of free time at one time, I decided to sort out a bit with the Plasma SDK, having implemented a function that I really didn’t have enough as part of my desktop at that time. And this function is an opportunity to send entries to LiveJournal without attracting additional applications. That is a sort of mini-client built right into the desktop. “It would be great,” I thought, and began to stir up the subject area of ​​interest.#ifndef __lj_plasmoid_h
#define __lj_plasmoid_h
#include <Plasma/Applet>
class QSizeF;
class LjPlasmoid : public Plasma::Applet
{
Q_OBJECT
public :
LjPlasmoid(QObject *parent, const QVariantList &args);
~LjPlasmoid();
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect);
void init();
};
#endif
* This source code was highlighted with Source Code Highlighter .
#ifndef __lj_plasmoid_h
#define __lj_plasmoid_h
#include <Plasma/Applet>
class QSizeF;
class LjPlasmoid : public Plasma::Applet
{
Q_OBJECT
public :
LjPlasmoid(QObject *parent, const QVariantList &args);
~LjPlasmoid();
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect);
void init();
};
#endif
* This source code was highlighted with Source Code Highlighter .
#ifndef __lj_plasmoid_h
#define __lj_plasmoid_h
#include <Plasma/Applet>
class QSizeF;
class LjPlasmoid : public Plasma::Applet
{
Q_OBJECT
public :
LjPlasmoid(QObject *parent, const QVariantList &args);
~LjPlasmoid();
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect& contentsRect);
void init();
};
#endif
* This source code was highlighted with Source Code Highlighter .
#include "lj_plasmoid.h"
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <plasma/svg.h>
#include <plasma/theme.h>
//
// .desktop
K_EXPORT_PLASMA_APPLET(ljplasmoid, LjPlasmoid)
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args)
{
//
//
setBackgroundHints(DefaultBackground);
resize(400, 300);
}
LjPlasmoid::~LjPlasmoid()
{
}
void LjPlasmoid::init()
{
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
//
}
* This source code was highlighted with Source Code Highlighter .
#include "lj_plasmoid.h"
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <plasma/svg.h>
#include <plasma/theme.h>
//
// .desktop
K_EXPORT_PLASMA_APPLET(ljplasmoid, LjPlasmoid)
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args)
{
//
//
setBackgroundHints(DefaultBackground);
resize(400, 300);
}
LjPlasmoid::~LjPlasmoid()
{
}
void LjPlasmoid::init()
{
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
//
}
* This source code was highlighted with Source Code Highlighter .
#include "lj_plasmoid.h"
#include <QPainter>
#include <QFontMetrics>
#include <QSizeF>
#include <plasma/svg.h>
#include <plasma/theme.h>
//
// .desktop
K_EXPORT_PLASMA_APPLET(ljplasmoid, LjPlasmoid)
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args)
{
//
//
setBackgroundHints(DefaultBackground);
resize(400, 300);
}
LjPlasmoid::~LjPlasmoid()
{
}
void LjPlasmoid::init()
{
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
//
}
* This source code was highlighted with Source Code Highlighter .
[Desktop Entry]
Name=LjPlasmoid
Comment=LiveJournal Plasmoid
Type=Service
ServiceTypes=Plasma/Applet
X-KDE-Library=plasma_applet_ljplasmoid
X-KDE-PluginInfo-Author=Ivan Ivanov
X-KDE-PluginInfo-Email=ivan.ivanov@mail.ru
X-KDE-PluginInfo-Name=ljplasmoid
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=Examples
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
project(ljplasmoid)
set(CMAKE_VERBOSE_MAKEFILE ON)
find_package(KDE4 REQUIRED)
include(KDE4Defaults)
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
set(ljplasmoid_SRCS lj_plasmoid.cpp)
kde4_add_plugin(plasma_applet_ljplasmoid ${ljplasmoid_SRCS})
target_link_libraries(plasma_applet_ljplasmoid ${KDE4_PLASMA_LIBS} ${KDE4_KDEUI_LIBS})
...
#include <Plasma/PushButton>
#include <Plasma/TextEdit>
...
class LjPlasmoid : public Plasma::Applet
{
...
public slots:
void PostPressed();
public :
Plasma::PushButton m_post_button;
Plasma::TextEdit m_text_edit;
};
* This source code was highlighted with Source Code Highlighter .
...
#include <Plasma/PushButton>
#include <Plasma/TextEdit>
...
class LjPlasmoid : public Plasma::Applet
{
...
public slots:
void PostPressed();
public :
Plasma::PushButton m_post_button;
Plasma::TextEdit m_text_edit;
};
* This source code was highlighted with Source Code Highlighter .
...
#include <Plasma/PushButton>
#include <Plasma/TextEdit>
...
class LjPlasmoid : public Plasma::Applet
{
...
public slots:
void PostPressed();
public :
Plasma::PushButton m_post_button;
Plasma::TextEdit m_text_edit;
};
* This source code was highlighted with Source Code Highlighter .
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args), m_post_button( this ), m_text_edit( this )
{
m_post_button.setText( "Post" );
m_text_edit.setText( "[ok: put your text here]" );
connect(&m_post_button, SIGNAL(clicked()), SLOT(PostPressed()));
setBackgroundHints(DefaultBackground);
resize(300, 200);
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
p->setRenderHint(QPainter::SmoothPixmapTransform);
p->setRenderHint(QPainter::Antialiasing);
m_post_button.setGeometry(QRect(contentsRect.x() + contentsRect.width() - 75,
contentsRect.y() + contentsRect.height() - 30, 10, 30));
m_text_edit.setGeometry(QRect(contentsRect.x(), contentsRect.y(),
contentsRect.width(), contentsRect.height() - 35));
}
* This source code was highlighted with Source Code Highlighter .
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args), m_post_button( this ), m_text_edit( this )
{
m_post_button.setText( "Post" );
m_text_edit.setText( "[ok: put your text here]" );
connect(&m_post_button, SIGNAL(clicked()), SLOT(PostPressed()));
setBackgroundHints(DefaultBackground);
resize(300, 200);
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
p->setRenderHint(QPainter::SmoothPixmapTransform);
p->setRenderHint(QPainter::Antialiasing);
m_post_button.setGeometry(QRect(contentsRect.x() + contentsRect.width() - 75,
contentsRect.y() + contentsRect.height() - 30, 10, 30));
m_text_edit.setGeometry(QRect(contentsRect.x(), contentsRect.y(),
contentsRect.width(), contentsRect.height() - 35));
}
* This source code was highlighted with Source Code Highlighter .
LjPlasmoid::LjPlasmoid(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args), m_post_button( this ), m_text_edit( this )
{
m_post_button.setText( "Post" );
m_text_edit.setText( "[ok: put your text here]" );
connect(&m_post_button, SIGNAL(clicked()), SLOT(PostPressed()));
setBackgroundHints(DefaultBackground);
resize(300, 200);
}
void LjPlasmoid::paintInterface(QPainter *p,
const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
p->setRenderHint(QPainter::SmoothPixmapTransform);
p->setRenderHint(QPainter::Antialiasing);
m_post_button.setGeometry(QRect(contentsRect.x() + contentsRect.width() - 75,
contentsRect.y() + contentsRect.height() - 30, 10, 30));
m_text_edit.setGeometry(QRect(contentsRect.x(), contentsRect.y(),
contentsRect.width(), contentsRect.height() - 35));
}
* This source code was highlighted with Source Code Highlighter .

void LjPlasmoid::PostPressed()
{
LjSession session;
LjRequest post(&session, recieve_responce, this );
post.AddData( "mode" , "postevent" );
post.AddData( "user" , "user_name" );
post.AddData( "password" , "user_password" );
post.AddData( "ver" , "1" );
post.AddData( "event" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.AddData( "lineendings" , "unix" );
post.AddData( "subject" , "[Posted via LjPlasmoid]" );
post.AddData( "security" , "public" );
post.AddData( "year" , "2009" );
post.AddData( "mon" , "11" );
post.AddData( "day" , "23" );
post.AddData( "hour" , "20" );
post.AddData( "min" , "00" );
printf( "text2send: %s\n" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.Post();
m_text_edit.setText( "[ok: put your text here]" );
}
* This source code was highlighted with Source Code Highlighter .
void LjPlasmoid::PostPressed()
{
LjSession session;
LjRequest post(&session, recieve_responce, this );
post.AddData( "mode" , "postevent" );
post.AddData( "user" , "user_name" );
post.AddData( "password" , "user_password" );
post.AddData( "ver" , "1" );
post.AddData( "event" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.AddData( "lineendings" , "unix" );
post.AddData( "subject" , "[Posted via LjPlasmoid]" );
post.AddData( "security" , "public" );
post.AddData( "year" , "2009" );
post.AddData( "mon" , "11" );
post.AddData( "day" , "23" );
post.AddData( "hour" , "20" );
post.AddData( "min" , "00" );
printf( "text2send: %s\n" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.Post();
m_text_edit.setText( "[ok: put your text here]" );
}
* This source code was highlighted with Source Code Highlighter .
void LjPlasmoid::PostPressed()
{
LjSession session;
LjRequest post(&session, recieve_responce, this );
post.AddData( "mode" , "postevent" );
post.AddData( "user" , "user_name" );
post.AddData( "password" , "user_password" );
post.AddData( "ver" , "1" );
post.AddData( "event" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.AddData( "lineendings" , "unix" );
post.AddData( "subject" , "[Posted via LjPlasmoid]" );
post.AddData( "security" , "public" );
post.AddData( "year" , "2009" );
post.AddData( "mon" , "11" );
post.AddData( "day" , "23" );
post.AddData( "hour" , "20" );
post.AddData( "min" , "00" );
printf( "text2send: %s\n" , m_text_edit.nativeWidget()->toPlainText().toAscii().data());
post.Post();
m_text_edit.setText( "[ok: put your text here]" );
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/76371/
All Articles