Commit 044c91d6 authored by Jekyll Wu's avatar Jekyll Wu
Browse files

Make sure the right item is operated on when changing startup type

The problem was the "current" item was sometime not the one you would
have expected when changing the startup type of item A:

  * it could be "none"
  * it could be the previous "current" item

The fix is a little hacky, but better than none.

BUG: 228795
FIXED-IN: 4.9.4
parent f7769851
......@@ -378,16 +378,17 @@ void Autostart::slotAdvanced() {
delete dlg;
}
void Autostart::slotChangeStartup( int index )
void Autostart::slotChangeStartup( ScriptStartItem* item, int index )
{
if ( widget->listCMD->currentItem() == 0 )
return;
ScriptStartItem* entry = dynamic_cast<ScriptStartItem*>( widget->listCMD->currentItem() );
if ( entry )
Q_ASSERT(item);
if ( item )
{
entry->setPath(m_paths.value(index));
if ( ( index != 0 ) && !entry->fileName().path().endsWith( ".sh" ))
item->setPath(m_paths.value(index));
widget->listCMD->setCurrentItem( item );
if ( ( index != 0 ) && !item->fileName().path().endsWith( ".sh" ))
KMessageBox::information( this, i18n( "Only files with “.sh” extensions are allowed for setting up the environment." ) );
}
}
......
......@@ -47,7 +47,7 @@ public:
QStringList listPathName() const { return m_pathName;}
public slots:
void slotChangeStartup( int index );
void slotChangeStartup( ScriptStartItem* item, int index );
protected:
void addItem(DesktopStartItem *item, const QString& name, const QString& run, const QString& command, bool disable );
......
......@@ -68,7 +68,8 @@ ScriptStartItem::ScriptStartItem( const QString &service, QTreeWidgetItem *paren
m_comboBoxStartup->addItems( autostart->listPathName() );
setText( 2, i18nc( "The program will be run", "Enabled" ) );
QObject::connect( m_comboBoxStartup, SIGNAL(activated(int)),autostart,SLOT(slotChangeStartup(int)) );
QObject::connect( m_comboBoxStartup,SIGNAL(activated(int)),this,SLOT(slotStartupChanged(int)) );
QObject::connect( this,SIGNAL(askChangeStartup(ScriptStartItem*,int)),autostart,SLOT(slotChangeStartup(ScriptStartItem*,int)) );
treeWidget()->setItemWidget ( this, Autostart::COL_RUN, m_comboBoxStartup );
}
......@@ -76,6 +77,11 @@ ScriptStartItem::~ScriptStartItem()
{
}
void ScriptStartItem::slotStartupChanged(int index)
{
emit askChangeStartup(this, index);
}
void ScriptStartItem::changeStartup(ScriptStartItem::ENV type )
{
switch( type )
......@@ -95,3 +101,4 @@ void ScriptStartItem::changeStartup(ScriptStartItem::ENV type )
}
}
#include "autostartitem.moc"
......@@ -21,13 +21,14 @@
#define _AUTOSTARTITEM_H_
#include <QTreeWidgetItem>
#include <QObject>
#include <KUrl>
class QComboBox;
class QTreeWidget;
class Autostart;
class AutoStartItem : public QTreeWidgetItem
class AutoStartItem : public QTreeWidgetItem, public QObject
{
public:
AutoStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* );
......@@ -51,6 +52,8 @@ public:
class ScriptStartItem : public AutoStartItem
{
Q_OBJECT
public:
enum ENV { START=0, SHUTDOWN=1, PRE_START=2}; //rename
ScriptStartItem( const QString &service, QTreeWidgetItem *parent, Autostart* );
......@@ -58,6 +61,13 @@ public:
void changeStartup( ScriptStartItem::ENV type );
signals:
void askChangeStartup(ScriptStartItem* item, int index);
private slots:
void slotStartupChanged(int index);
private:
QComboBox *m_comboBoxStartup;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment