qrcupdate-0.1.0/0000755000175000001440000000000010362161733012735 5ustar tasukuusersqrcupdate-0.1.0/src/0000755000175000001440000000000010362161733013524 5ustar tasukuusersqrcupdate-0.1.0/src/qrucell.h0000644000175000001440000000411310362040417015336 0ustar tasukuusers/*************************************************************************** * Copyright (C) 2006 by SUZUKI Tasuku * * tasuku@linux-life.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef QRUCELL_H #define QRUCELL_H #include class QPixmap; /** @author SUZUKI Tasuku */ class QRUCell : public QWidget { Q_OBJECT public: QRUCell( const QString& runlevel, const QString& script, bool readOnly, QWidget* parent = 0, const char* name = 0 ); ~QRUCell(); public slots: void save(); protected: void paintEvent( QPaintEvent* e ); void mouseDoubleClickEvent( QMouseEvent* e ); private: bool m_readOnly; QString m_file; QString m_script; bool m_initial; bool m_current; QPixmap* m_on; QPixmap* m_off; QPixmap* m_onDirty; QPixmap* m_offDirty; QPixmap* getPixmap(); QPixmap* paintRound( QColor color ); }; #endif qrcupdate-0.1.0/src/main.cpp0000644000175000001440000000332410361761553015163 0ustar tasukuusers/*************************************************************************** * Copyright (C) 2006 by SUZUKI Tasuku * * tasuku@linux-life.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include "qrcupdate.h" int main( int argc, char **argv ) { QApplication a( argc, argv ); QRcUpdate* mw = new QRcUpdate(); mw->setCaption( "QRcUpdate" ); mw->show(); a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) ); return a.exec(); } qrcupdate-0.1.0/src/src.pro0000644000175000001440000000057710361765667015065 0ustar tasukuusers# File generated by kdevelop's qmake manager. # ------------------------------------------- # Subdir relative project main directory: ./src # Target is ????????: ../bin/qrcupdate HEADERS += qrcupdate.h \ qrucell.h SOURCES += qrcupdate.cpp \ main.cpp \ qrucell.cpp TEMPLATE = app CONFIG += release \ warn_on \ thread \ qt TARGET = ../bin/qrcupdate qrcupdate-0.1.0/src/qrucell.cpp0000644000175000001440000001224110362040447015675 0ustar tasukuusers/*************************************************************************** * Copyright (C) 2006 by SUZUKI Tasuku * * tasuku@linux-life.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "qrucell.h" #include #include #include #include QRUCell::QRUCell( const QString& runlevel, const QString& script, bool readOnly, QWidget* parent, const char* name ) : QWidget( parent, name ) { m_readOnly = readOnly; m_file = "/etc/runlevels/" + runlevel + "/" + script; m_script = "/etc/init.d/" + script; m_initial = QFile::exists( m_file ); m_current = m_initial; m_on = m_onDirty = m_off = m_offDirty = 0; getPixmap(); } QRUCell::~QRUCell() { if( m_on ) delete m_on; if( m_onDirty ) delete m_onDirty; if( m_off ) delete m_off; if( m_offDirty ) delete m_offDirty; } void QRUCell::save() { if( m_initial != m_current ) { if( m_current ) { system( QString( "ln -s %1 %2" ).arg( m_script ).arg( m_file ) ); } else { QFile::remove( m_file ); } m_initial = m_current; update(); } } void QRUCell::mouseDoubleClickEvent( QMouseEvent* ) { if( m_readOnly ) return; m_current = !m_current; update(); } void QRUCell::paintEvent( QPaintEvent* ) { QPainter paint( this ); paint.drawPixmap( ( width() - height() ) / 2 + 2, 2, *getPixmap() ); } QPixmap* QRUCell::getPixmap() { QPixmap* pix = 0; QColor c; if( m_current ) { if( m_initial ) { pix = m_on; c = green; } else { pix = m_onDirty; c = red; } } else { if( m_initial ) { pix = m_offDirty; c = red.dark( 300 ); } else { pix = m_off; c = green.dark( 300 ); } } if( !pix ) { pix = paintRound( c ); } return pix; } // see kled.cpp QPixmap* QRUCell::paintRound( QColor color ) { QPainter paint; QBrush brush; QPen pen; // Initialize coordinates, width, and height of the LED int w = height() - 4; int scale = 3; w *= scale; QPixmap tmpMap( w+6, w+6 ); tmpMap.fill( paletteBackgroundColor() ); paint.begin( &tmpMap ); // Set the brush to SolidPattern, this fills the entire area // of the ellipse which is drawn first brush.setStyle( QBrush::SolidPattern ); brush.setColor( color ); paint.setBrush( brush ); // Assign the brush to the painter // Draws a "flat" LED with the given color: paint.drawEllipse( scale, scale, w - scale*2, w - scale*2 ); // Setting the new width of the pen is essential to avoid "pixelized" // shadow like it can be observed with the old LED code pen.setWidth( 2 * scale ); // shrink the light on the LED to a size about 2/3 of the complete LED int pos = w/5 + 1; int light_width = w; light_width *= 2; light_width /= 3; int light_quote = (130*2/(light_width?light_width:1))+100; // Now draw the bright spot on the LED: while (light_width) { color = color.light( light_quote ); // make color lighter pen.setColor( color ); // set color as pen color paint.setPen( pen ); // select the pen for drawing paint.drawEllipse( pos, pos, light_width, light_width ); // draw the ellipse (circle) light_width--; if (!light_width) break; paint.drawEllipse( pos, pos, light_width, light_width ); light_width--; if (!light_width) break; paint.drawEllipse( pos, pos, light_width, light_width ); pos++; light_width--; } // Drawing of bright spot finished, now draw a thin gray border // around the LED; it looks nicer that way. We do this here to // avoid that the border can be erased by the bright spot of the LED pen.setWidth( 2 * scale + 1 ); color = colorGroup().dark(); pen.setColor( color ); // Set the pen accordingly paint.setPen( pen ); // Select pen for drawing brush.setStyle( QBrush::NoBrush ); // Switch off the brush paint.setBrush( brush ); // This avoids filling of the ellipse paint.drawEllipse( 2, 2, w, w ); paint.end(); // // painting done QImage i = tmpMap.convertToImage(); w /= 3; i = i.smoothScale(w, w); return new QPixmap( i ); } qrcupdate-0.1.0/src/qrcupdate.h0000644000175000001440000000345410362040247015667 0ustar tasukuusers/*************************************************************************** * Copyright (C) 2006 by SUZUKI Tasuku * * tasuku@linux-life.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef _QRCUPDATE_H_ #define _QRCUPDATE_H_ #include #include class QRUCell; class QRcUpdate: public QMainWindow { Q_OBJECT public: QRcUpdate(); ~QRcUpdate(); private slots: void about(); void aboutQt(); void save(); void apply(); private: QPtrList m_cells; QStringList m_runlevels; QStringList m_scripts; }; #endif qrcupdate-0.1.0/src/qrcupdate.cpp0000644000175000001440000001236410362153475016232 0ustar tasukuusers/*************************************************************************** * Copyright (C) 2006 by SUZUKI Tasuku * * tasuku@linux-life.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "qrcupdate.h" #include "qrucell.h" #include #include #include #include #include #include #include #include #include #include QRcUpdate::QRcUpdate() : QMainWindow( 0, "QRcUpdate" ) { QFileInfo fi( "/etc/runlevels/" ); bool readOnly = !fi.isWritable(); QDir runlevels( "/etc/runlevels", QString::null, QDir::Name, QDir::Dirs ); for( uint i = 0; i != runlevels.count(); i++ ) { if( runlevels[i].left( 1 ) == "." ) continue; m_runlevels << runlevels[i]; } QDir scripts( "/etc/init.d", QString::null, QDir::Name, QDir::Files | QDir::Executable ); for( uint i = 0; i != scripts.count(); i++ ) { if( scripts[i].right( 3 ) == ".sh" ) continue; m_scripts << scripts[i]; } QVBox* vbox = new QVBox( this ); if( readOnly ) { new QLabel( tr( "You don't have permission to update!" ), vbox ); } QTable* table = new QTable( m_scripts.count(), m_runlevels.count(), vbox ); QHeader* header; header = table->horizontalHeader(); for( uint i = 0; i != m_runlevels.count(); i++ ) { header->setLabel( i, m_runlevels[i] ); } header->setClickEnabled( false ); header->setResizeEnabled( false ); header->setMovingEnabled( false ); header->setStretchEnabled( false ); header = table->verticalHeader(); for( uint i = 0; i != m_scripts.count(); i++ ) { header->setLabel( i, m_scripts[i] ); } header->setClickEnabled( false ); header->setResizeEnabled( false ); header->setMovingEnabled( false ); header->setStretchEnabled( false ); for( uint col = 0; col != m_runlevels.count(); col++ ) { for( uint row = 0; row != m_scripts.count(); row++ ) { QRUCell* cell = new QRUCell( m_runlevels[col], m_scripts[row], readOnly, table ); table->setCellWidget( row, col, cell ); m_cells.append( cell ); } } QWidget* footer = new QWidget( vbox ); QHBoxLayout* layout = new QHBoxLayout( footer, 5 ); QPushButton* btn = new QPushButton( tr( "A&bout" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( about() ) ); layout->addWidget( btn ); btn = new QPushButton( tr( "About &Qt" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( aboutQt() ) ); layout->addWidget( btn ); layout->addStretch(); if( readOnly ) { btn = new QPushButton( tr( "&Close" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( close() ) ); layout->addWidget( btn ); } else { btn = new QPushButton( tr( "&OK" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( save() ) ); layout->addWidget( btn ); btn = new QPushButton( tr( "&Apply" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( apply() ) ); layout->addWidget( btn ); btn = new QPushButton( tr( "&Cancel" ), footer ); connect( btn, SIGNAL( clicked() ), this, SLOT( close() ) ); layout->addWidget( btn ); } setCentralWidget( vbox ); } QRcUpdate::~QRcUpdate() { } void QRcUpdate::about() { QMessageBox::about( this, tr( "About QRcUpdate" ), tr( "GUI style rc-update for Gentoo
" ) + tr( "
" ) + tr( "Copyright (C) 2006
" ) + tr( "By SUZUKI Tasuku
" ) + tr( "tasuku@linux-life.net
" ) + tr( "https://linux-life.net/program/cc/kde/app/qrcupdate/
" ) + tr( "
" ) + tr( "QRcUpdate is free software, covered by the GNU General Public License, " ) + tr( "and you are welcome to change it and/or distribute copies of it under certain conditions." ) ); } void QRcUpdate::aboutQt() { QMessageBox::aboutQt( this, tr( "About Qt" ) ); } void QRcUpdate::save() { apply(); close(); } void QRcUpdate::apply() { QApplication::setOverrideCursor( Qt::waitCursor ); for( QRUCell* cell = m_cells.first(); cell; cell = m_cells.next() ) { cell->save(); } QApplication::restoreOverrideCursor(); } qrcupdate-0.1.0/qrcupdate.pro0000644000175000001440000000015410361760515015451 0ustar tasukuusersSUBDIRS += src TEMPLATE = subdirs CONFIG += release \ warn_on \ qt \ thread