summaryrefslogtreecommitdiff
path: root/core/settings/launcher/menusettings.cpp
blob: 29ce8414d5803719916e6b611ac1788ffd9b23fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
                     This file is part of the OPIE Project
               =.            Copyright (c)  2002 Trolltech AS <info@trolltech.com>
      .=l.            Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
     .>+-=
_;:,   .>  :=|.         This file is free software; you can
.> <`_,  > .  <=          redistribute it and/or modify it under
:`=1 )Y*s>-.--  :           the terms of the GNU General Public
.="- .-=="i,   .._         License as published by the Free Software
- .  .-<_>   .<>         Foundation; either version 2 of the License,
  ._= =}    :          or (at your option) any later version.
  .%`+i>    _;_.
  .i_,=:_.   -<s.       This file 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 file;
 -_. . .  )=. =           see the file COPYING. If not, write to the
  --    :-=`           Free Software Foundation, Inc.,
                             59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.

*/

#include "menusettings.h"

#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/qpeapplication.h>
#include <qpe/menuappletinterface.h>
#include <qpe/qcopenvelope_qws.h>

#include <qdir.h>
#include <qlistview.h>
#include <qcheckbox.h>
#include <qheader.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qwhatsthis.h>

#include <stdlib.h>


MenuSettings::MenuSettings ( QWidget *parent, const char *name )
	: QWidget ( parent, name )
{
	m_applets_changed = false;

	QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 );

	QLabel *l = new QLabel ( tr( "Load applets in O-Menu:" ), this );
	lay-> addWidget ( l );

	m_list = new QListView ( this );
	m_list-> addColumn ( "foobar" );
	m_list-> header ( )-> hide ( );

	lay-> addWidget ( m_list );

	m_menutabs = new QCheckBox ( tr( "Show Launcher tabs in O-Menu" ), this );
	lay-> addWidget ( m_menutabs );

	m_menusubpopup = new QCheckBox ( tr( "Show Applications in Subpopups" ), this );
	lay-> addWidget ( m_menusubpopup );

	QWhatsThis::add ( m_list, tr( "Check the applets that you want to have included in the O-Menu." ));
	QWhatsThis::add ( m_menutabs, tr( "Adds the contents of the Launcher Tabs as menus in the O-Menu." ));

	connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged()));

	init ( );
}

void MenuSettings::init ( )
{
	Config cfg ( "StartMenu" );
	cfg. setGroup ( "Applets" );
	QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' );

	QString path = QPEApplication::qpeDir ( ) + "plugins/applets";
#ifdef Q_OS_MACX
	QStringList list = QDir ( path, "lib*.dylib" ). entryList ( );
#else
	QStringList list = QDir ( path, "lib*.so" ). entryList ( );
#endif /* Q_OS_MACX */

	for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) {
		QString name;
		QPixmap icon;
		MenuAppletInterface *iface = 0;

		QLibrary *lib = new QLibrary ( path + "/" + *it );
		lib-> queryInterface ( IID_MenuApplet, (QUnknownInterface**) &iface );
        if ( iface ) {
			QString lang = getenv( "LANG" );
			QTranslator *trans = new QTranslator ( qApp );
			QString type = (*it). left ((*it). find ("."));
			QString tfn = QPEApplication::qpeDir ( ) + "i18n/" + lang + "/" + type + ".qm";
			if ( trans-> load ( tfn ))
				qApp-> installTranslator ( trans );
			else
				delete trans;
			name = iface-> name ( );
			icon = iface-> icon ( ). pixmap ();
			iface-> release ( );
			lib-> unload ( );

			QCheckListItem *item;
			item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox );
			if ( !icon. isNull ( ))
				item-> setPixmap ( 0, icon );
			item-> setOn ( exclude. find ( *it ) == exclude. end ( ));
			m_applets [*it] = item;
		} else {
			delete lib;
		}
	}

	cfg. setGroup ( "Menu" );
        m_menutabs->setChecked( cfg.readBoolEntry( "LauncherTabs", true ) );
        m_menusubpopup->setChecked( cfg.readBoolEntry( "LauncherSubPopup", true ) );
        m_menusubpopup->setEnabled( m_menutabs->isChecked() );
        connect( m_menutabs, SIGNAL( stateChanged(int) ), m_menusubpopup, SLOT( setEnabled(bool) ) );

}

void MenuSettings::appletChanged()
{
	m_applets_changed = true;
}

void MenuSettings::accept ( )
{
	bool apps_changed = false;

	Config cfg ( "StartMenu" );
	cfg. setGroup ( "Applets" );
	if ( m_applets_changed ) {
		QStringList exclude;
		QMap <QString, QCheckListItem *>::Iterator it;
		for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) {
			if ( !(*it)-> isOn ( ))
				exclude << it. key ( );
		}
		cfg. writeEntry ( "ExcludeApplets", exclude, ',' );
	}
	cfg. writeEntry ( "SafeMode", false );

	cfg. setGroup ( "Menu" );

	if ( m_menutabs-> isChecked ( ) != cfg. readBoolEntry ( "LauncherTabs", true )) {
		apps_changed = true;
		cfg. writeEntry ( "LauncherTabs", m_menutabs-> isChecked ( ));
	}

                if ( m_menusubpopup-> isChecked ( ) != cfg. readBoolEntry ( "LauncherSubPopup", true )) {
		 apps_changed = true;
		cfg. writeEntry ( "LauncherSubPopup", m_menusubpopup-> isChecked ( ));
	}

	cfg. write ( );

	if ( m_applets_changed ) {
		QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
		m_applets_changed = false;
	}
	if ( apps_changed ) {
                                 // currently use reloadApplets() since reloadApps is now used exclusive for server
                                 // to refresh the tabs. But what we want here is also a refresh of the startmenu entries
		QCopEnvelope ( "QPE/TaskBar", "reloadApps()" );
                                QCopEnvelope ( "QPE/TaskBar", "reloadApplets()" );
	}
}