~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy-backports

« back to all changes in this revision

Viewing changes to kicker/menuext/konq-profiles/konqy_menu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 
 
3
Copyright (c) 1996-2001 the kicker authors. See file AUTHORS.
 
4
 
 
5
Permission is hereby granted, free of charge, to any person obtaining a copy
 
6
of this software and associated documentation files (the "Software"), to deal
 
7
in the Software without restriction, including without limitation the rights
 
8
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
9
copies of the Software, and to permit persons to whom the Software is
 
10
furnished to do so, subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
******************************************************************/
 
23
 
 
24
#include "konqy_menu.h"
 
25
#include <kiconloader.h>
 
26
#include <klocale.h>
 
27
#include <kglobal.h>
 
28
#include <kapplication.h>
 
29
#include <krun.h>
 
30
#include <kstandarddirs.h>
 
31
#include <kio/global.h>
 
32
#include <kconfig.h>
 
33
 
 
34
#include <QRegExp>
 
35
#include <QFileInfo>
 
36
#include <ktoolinvocation.h>
 
37
 
 
38
K_EXPORT_KICKER_MENUEXT(konqueror, KonquerorProfilesMenu)
 
39
 
 
40
KonquerorProfilesMenu::KonquerorProfilesMenu(QWidget *parent, const QStringList & /*args*/)
 
41
: KPanelMenu("", parent)
 
42
{
 
43
    static bool kdeprintIconsInitialized = false;
 
44
    if ( !kdeprintIconsInitialized ) {
 
45
        KIconLoader::global()->addAppDir("kdeprint");
 
46
        kdeprintIconsInitialized = true;
 
47
    }
 
48
}
 
49
 
 
50
KonquerorProfilesMenu::~KonquerorProfilesMenu()
 
51
{
 
52
}
 
53
 
 
54
void KonquerorProfilesMenu::initialize()
 
55
{
 
56
   if (initialized()) clear();
 
57
   setInitialized(true);
 
58
 
 
59
   QStringList profiles = KGlobal::dirs()->findAllResources( "data", "konqueror/profiles/*", KStandardDirs::NoDuplicates );
 
60
 
 
61
   m_profiles.resize(profiles.count());
 
62
   int id=1;
 
63
   QStringList::ConstIterator pEnd = profiles.end();
 
64
   for (QStringList::ConstIterator pIt = profiles.begin(); pIt != pEnd; ++pIt )
 
65
   {
 
66
      QFileInfo info( *pIt );
 
67
      QString profileName = KIO::decodeFileName( info.baseName() );
 
68
      QString niceName=profileName;
 
69
      KConfig cfg( *pIt, KConfig::OnlyLocal);
 
70
      if ( cfg.hasGroup( "Profile" ) )
 
71
      {
 
72
                 KConfigGroup cg(&cfg, "Profile" );
 
73
         if ( cg.hasKey( "Name" ) )
 
74
            niceName = cg.readEntry( "Name" );
 
75
 
 
76
         insertItem(niceName, id);
 
77
         m_profiles[id-1]=profileName;
 
78
         id++;
 
79
      }
 
80
   }
 
81
}
 
82
 
 
83
void KonquerorProfilesMenu::slotExec(int id)
 
84
{
 
85
   QStringList args;
 
86
   args<<"--profile"<<m_profiles[id-1];
 
87
   KToolInvocation::kdeinitExec("konqueror", args);
 
88
}
 
89
 
 
90
void KonquerorProfilesMenu::reload()
 
91
{
 
92
   initialize();
 
93
}
 
94
 
 
95
void KonquerorProfilesMenu::slotAboutToShow()
 
96
{
 
97
    reinitialize();
 
98
    KPanelMenu::slotAboutToShow();
 
99
}
 
100
 
 
101
 
 
102
#include "konqy_menu.moc"
 
103