• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
tdefilespeedbar.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
3 
4  library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation, version 2.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "tdefilespeedbar.h"
20 #include "config-tdefile.h"
21 
22 #include <tqdir.h>
23 #include <tqfile.h>
24 #include <tqtextcodec.h>
25 #include <tqtextstream.h>
26 
27 #include <tdeconfig.h>
28 #include <tdeglobal.h>
29 #include <tdeglobalsettings.h>
30 #include <tdelocale.h>
31 #include <kprotocolinfo.h>
32 #include <kstandarddirs.h>
33 #include <kurl.h>
34 
35 KFileSpeedBar::KFileSpeedBar( TQWidget *parent, const char *name )
36  : KURLBar( true, parent, name )
37 {
38  TDEConfig *config = TDEGlobal::config();
39  TDEConfigGroupSaver cs( config, ConfigGroup );
40  m_initializeSpeedbar = config->readBoolEntry( "Set speedbar defaults",
41  true );
42  setIconSize(TDEIcon::SizeSmallMedium);
43  readConfig( TDEGlobal::config(), "KFileDialog Speedbar" );
44 
45  if ( m_initializeSpeedbar )
46  {
47  KURL u;
48  u.setPath( TDEGlobalSettings::desktopPath() );
49  insertItem( u, i18n("Desktop"), false );
50 
51 //TODO: win32
52  if ((TDEGlobalSettings::documentPath() != (TQDir::homeDirPath()+"/")) &&
53  TQDir(TDEGlobalSettings::documentPath()).exists())
54  {
55  u.setPath( TDEGlobalSettings::documentPath() );
56  insertItem( u, i18n("Documents"), false, "folder_txt" );
57  }
58 
59  u.setPath( TQDir::homeDirPath() );
60  insertItem( u, i18n("Home Folder"), false,
61  "folder_home" );
62 
63  u = "media:/";
64  if ( KProtocolInfo::isKnownProtocol( u ) )
65  insertItem( u, i18n("Storage Media"), false,
66  KProtocolInfo::icon( "media" ) );
67 
68  if ( TQFile::exists( TQDir::homeDirPath()+"/.config/user-dirs.dirs" ) )
69  {
70  TQString download, music, pictures, videos, templates, publicShares;
71 
72  TQFile f( TQDir::homeDirPath()+"/.config/user-dirs.dirs" );
73  if (!f.open(IO_ReadOnly))
74  return;
75 
76  TQTextStream s( &f );
77  s.setCodec( TQTextCodec::codecForLocale() );
78 
79  // read the xdg user dirs
80  TQString line = s.readLine();
81  while (!line.isNull())
82  {
83  if (line.startsWith("XDG_DOWNLOAD_DIR="))
84  download = line.remove("XDG_DOWNLOAD_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
85  else if (line.startsWith("XDG_MUSIC_DIR="))
86  music = line.remove("XDG_MUSIC_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
87  else if (line.startsWith("XDG_PICTURES_DIR="))
88  pictures = line.remove("XDG_PICTURES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
89  else if (line.startsWith("XDG_VIDEOS_DIR="))
90  videos = line.remove("XDG_VIDEOS_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
91  else if (line.startsWith("XDG_TEMPLATES_DIR="))
92  templates = line.remove("XDG_TEMPLATES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
93  else if (line.startsWith("XDG_PUBLICSHARES_DIR="))
94  publicShares = line.remove("XDG_PUBLICSHARES_DIR=").remove("\"").replace("$HOME", TQDir::homeDirPath());
95 
96  line = s.readLine();
97  }
98  // now add in the speedbar
99  if (!download.isEmpty())
100  insertItem( download, i18n( "Downloads" ), false, "folder_html" );
101  if (!music.isEmpty())
102  insertItem( music, i18n( "Music" ), false, "folder_sound" );
103  if (!pictures.isEmpty())
104  insertItem( pictures, i18n( "Pictures" ), false, "folder_image" );
105  if (!videos.isEmpty())
106  insertItem( videos, i18n( "Videos" ), false, "folder_video" );
107  if (!templates.isEmpty())
108  insertItem( templates, i18n( "Templates" ), false, "folder_video" );
109  if (!publicShares.isEmpty())
110  insertItem( publicShares, i18n( "Public" ), false, "folder_video" );
111  }
112 
113  u = "remote:/";
114  if ( KProtocolInfo::isKnownProtocol( u ) )
115  insertItem( u, i18n("Network Folders"), false,
116  KProtocolInfo::icon( "remote" ) );
117  }
118 }
119 
120 KFileSpeedBar::~KFileSpeedBar()
121 {
122 }
123 
124 void KFileSpeedBar::save( TDEConfig *config )
125 {
126  if ( m_initializeSpeedbar && isModified() )
127  {
128  TDEConfigGroup conf( config, ConfigGroup );
129  // write to kdeglobals
130  conf.writeEntry( "Set speedbar defaults", false, true, true );
131  }
132 
133  writeConfig( config, "KFileDialog Speedbar" );
134 }
135 
136 TQSize KFileSpeedBar::sizeHint() const
137 {
138  TQSize sizeHint = KURLBar::sizeHint();
139  int ems = fontMetrics().width("mmmmmmmmmmmm");
140  if (sizeHint.width() < ems)
141  {
142  sizeHint.setWidth(ems);
143  }
144  return sizeHint;
145 }
146 
147 #include "tdefilespeedbar.moc"
KURLBar
KURLBar is a widget that displays icons together with a description.
Definition: kurlbar.h:230
KURLBar::sizeHint
virtual TQSize sizeHint() const
Definition: kurlbar.cpp:471

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.8.13
This website is maintained by Timothy Pearson.