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

Konsole

kwrited.cpp

Go to the documentation of this file.
00001 /*
00002     kwrited is a write(1) receiver for KDE.
00003     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018     02110-1301  USA.
00019 */
00020 
00021 // Own
00022 #include "kwrited.h"
00023 
00024 #include <QtCore/QSocketNotifier>
00025 #include <QtGui/QKeyEvent>
00026 
00027 #include <kuniqueapplication.h>
00028 #include <kcmdlineargs.h>
00029 #include <klocale.h>
00030 #include <kglobalsettings.h>
00031 #include <kdebug.h>
00032 #include <kcrash.h>
00033 #include <kpty.h>
00034 #include <kuser.h>
00035 #include <kglobal.h>
00036 
00037 
00038 #include <stdlib.h>
00039 #include <unistd.h>
00040 #include <stdio.h>
00041 #include <signal.h>
00042 
00043 #ifdef Q_WS_X11
00044 #include <X11/Xlib.h>
00045 #include <fixx11h.h>
00046 #endif
00047 
00048 #include <kpluginfactory.h>
00049 #include <kpluginloader.h>
00050 
00051 K_PLUGIN_FACTORY(KWritedFactory,
00052                  registerPlugin<KWritedModule>();
00053     )
00054 K_EXPORT_PLUGIN(KWritedFactory("konsole"))
00055 
00056 
00057 /* TODO
00058    for anyone who likes to do improvements here, go ahead.
00059    - check FIXMEs below
00060    - add Menu
00061      - accept messages (on/off)
00062      - pop up on incoming messages
00063      - clear messages
00064      - allow max. lines
00065    - add DBus interface?
00066    - add session awareness.
00067    - add client complements.
00068    - kwrited is disabled by default if built without utempter,
00069      see ../Makefile.am - kwrited doesn't seem to work well without utempter
00070 */
00071 
00072 KWrited::KWrited() : QTextEdit()
00073 {
00074   int pref_width, pref_height;
00075 
00076   setFont(KGlobalSettings::fixedFont());
00077   pref_width = (2 * KGlobalSettings::desktopGeometry(0).width()) / 3;
00078   pref_height = fontMetrics().lineSpacing() * 10;
00079   setMinimumWidth(pref_width);
00080   setMinimumHeight(pref_height);
00081   setReadOnly(true);
00082 //  setFocusPolicy(QWidget::NoFocus);
00083 //  setWordWrap(QTextEdit::WidgetWidth);
00084 //  setTextFormat(Qt::PlainText);
00085 
00086   pty = new KPty();
00087   pty->open();
00088   pty->login(KUser().loginName().toLocal8Bit().data(), getenv("DISPLAY"));
00089   QSocketNotifier *sn = new QSocketNotifier(pty->masterFd(), QSocketNotifier::Read, this);
00090   connect(sn, SIGNAL(activated(int)), this, SLOT(block_in(int)));
00091 
00092   QString txt = i18n("KWrited - Listening on Device %1", pty->ttyName());
00093   setWindowTitle(txt);
00094   puts(txt.toLocal8Bit().data());
00095 }
00096 
00097 KWrited::~KWrited()
00098 {
00099     pty->logout();
00100     delete pty;
00101 }
00102 
00103 void KWrited::block_in(int fd)
00104 {
00105   char buf[4096];
00106   int len = read(fd, buf, 4096);
00107   if (len <= 0)
00108      return;
00109 
00110   insertPlainText( QString::fromLocal8Bit( buf, len ).remove('\r') );
00111   show();
00112   raise();
00113 }
00114 
00115 void KWrited::clearText()
00116 {
00117    clear();
00118 }
00119 
00120 void KWrited::contextMenuEvent(QContextMenuEvent * e)
00121 {
00122    QMenu *menu = createStandardContextMenu();
00123    menu->addAction("Clear Messages");
00124    // Add connection and shortcut if possible
00125    menu->exec(e->globalPos());
00126    delete menu;
00127 }
00128 
00129 KWritedModule::KWritedModule(QObject* parent, const QList<QVariant>&)
00130     : KDEDModule(parent)
00131 {
00132     // Done by the factory now
00133     //KGlobal::locale()->insertCatalog("konsole");
00134     pro = new KWrited;
00135 }
00136 
00137 KWritedModule::~KWritedModule()
00138 {
00139     delete pro;
00140     // Done by the factory now
00141     //KGlobal::locale()->removeCatalog("konsole");
00142 }
00143 
00144 #include "kwrited.moc"

Konsole

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

API Reference

Skip menu "API Reference"
  • Konsole
  • Libraries
  •   libkonq
Generated for API Reference by doxygen 1.5.4
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