• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
ProfileWriter.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Konsole, a terminal emulator.
3 
4  Copyright 2006-2008 by Robert Knight <robertknight@gmail.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301 USA.
20 */
21 
22 // Own
23 #include "ProfileWriter.h"
24 
25 // Qt
26 #include <QtCore/QFileInfo>
27 
28 // KDE
29 #include <KConfig>
30 #include <KConfigGroup>
31 #include <KGlobal>
32 #include <KStandardDirs>
33 
34 // Konsole
35 #include "ShellCommand.h"
36 
37 using namespace Konsole;
38 
39 // FIXME: A dup line from Profile.cpp - redo these
40 static const char GENERAL_GROUP[] = "General";
41 
42 QString KDE4ProfileWriter::getPath(const Profile::Ptr profile)
43 {
44  // both location have trailing slash
45  static const QString localDataLocation = KGlobal::dirs()->saveLocation("data", "konsole/");
46  static const QString systemDataLocation = KStandardDirs::installPath("data") + "konsole/";
47 
48  const QString candidateLocalPath = localDataLocation + profile->untranslatedName() + ".profile";
49  QString newPath;
50 
51  // when the path property is not set, it means the profile has just
52  // been created in memory and has never been saved into disk before.
53  //
54  // use "name.profile" as filename and save it under $KDEHOME
55  if (!profile->isPropertySet(Profile::Path)) {
56  return candidateLocalPath;
57  }
58 
59  // for a system wide profile, save the modified version as
60  // a local profile under $KDEHOME
61  if (profile->path().startsWith(systemDataLocation)) {
62  return candidateLocalPath;
63  }
64 
65  // for a local profile, use its existing path
66  if (profile->path().startsWith(localDataLocation)) {
67  newPath = profile->path();
68  } else {
69  // for the ad-hoc profiles in non-standard places
70  //
71  // * if its path is writable for user, use its existing path
72  // * if its path is not writable for user, save it under $KDEHOME
73  //
74  QFileInfo fileInfo(profile->path());
75  if (fileInfo.isWritable()) {
76  newPath = profile->path();
77  } else {
78  newPath = candidateLocalPath;
79  }
80  }
81 
82  return newPath;
83 }
84 void KDE4ProfileWriter::writeProperties(KConfig& config,
85  const Profile::Ptr profile,
86  const Profile::PropertyInfo* properties)
87 {
88  const char* groupName = 0;
89  KConfigGroup group;
90 
91  while (properties->name != 0) {
92  if (properties->group != 0) {
93  if (groupName == 0 || qstrcmp(groupName, properties->group) != 0) {
94  group = config.group(properties->group);
95  groupName = properties->group;
96  }
97 
98  if (profile->isPropertySet(properties->property))
99  group.writeEntry(QString(properties->name),
100  profile->property<QVariant>(properties->property));
101  }
102 
103  properties++;
104  }
105 }
106 bool KDE4ProfileWriter::writeProfile(const QString& path , const Profile::Ptr profile)
107 {
108  KConfig config(path, KConfig::NoGlobals);
109 
110  KConfigGroup general = config.group(GENERAL_GROUP);
111 
112  // Parent profile if set, when loading the profile in future, the parent
113  // must be loaded as well if it exists.
114  if (profile->parent())
115  general.writeEntry("Parent", profile->parent()->path());
116 
117  if (profile->isPropertySet(Profile::Command)
118  || profile->isPropertySet(Profile::Arguments))
119  general.writeEntry("Command",
120  ShellCommand(profile->command(), profile->arguments()).fullCommand());
121 
122  // Write remaining properties
123  writeProperties(config, profile, Profile::DefaultPropertyNames);
124 
125  return true;
126 }
127 
ShellCommand.h
Konsole::Profile::Command
(QString) The command to execute ( excluding arguments ) when creating a new terminal session using t...
Definition: Profile.h:93
Konsole::KDE4ProfileWriter::writeProfile
virtual bool writeProfile(const QString &path, const Profile::Ptr profile)
Writes the properties and values from profile to the file specified by path.
Definition: ProfileWriter.cpp:106
Konsole::ShellCommand
A class to parse and extract information about shell commands.
Definition: ShellCommand.h:52
Konsole::Profile::Arguments
(QStringList) The arguments which are passed to the program specified by the Command property when cr...
Definition: Profile.h:98
QString
QFileInfo
Konsole::Profile::Ptr
KSharedPtr< Profile > Ptr
Definition: Profile.h:67
GENERAL_GROUP
static const char GENERAL_GROUP[]
Definition: ProfileWriter.cpp:40
ProfileWriter.h
Konsole::KDE4ProfileWriter::getPath
virtual QString getPath(const Profile::Ptr profile)
Returns a suitable path-name for writing profile to.
Definition: ProfileWriter.cpp:42
Konsole::Profile::Path
(QString) Path to the profile's configuration file on-disk.
Definition: Profile.h:79
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal