Merge lp:~smspillaz/compiz-core/compiz-core.drop-ini-plugin into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Merged at revision: 2954
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.drop-ini-plugin
Merge into: lp:compiz-core/0.9.5
Diff against target: 759 lines (+0/-737)
4 files modified
plugins/ini/CMakeLists.txt (+0/-5)
plugins/ini/ini.xml.in (+0/-13)
plugins/ini/src/ini.cpp (+0/-614)
plugins/ini/src/ini.h (+0/-105)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.drop-ini-plugin
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+89756@code.launchpad.net

Description of the change

Drop the ini plugin.

Users should use the compizconfig ini backend. Seriously

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Sounds fine to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'plugins/ini'
2=== removed file 'plugins/ini/CMakeLists.txt'
3--- plugins/ini/CMakeLists.txt 2009-03-15 05:09:18 +0000
4+++ plugins/ini/CMakeLists.txt 1970-01-01 00:00:00 +0000
5@@ -1,5 +0,0 @@
6-find_package (Compiz REQUIRED)
7-
8-include (CompizPlugin)
9-
10-compiz_plugin(ini)
11\ No newline at end of file
12
13=== removed file 'plugins/ini/ini.xml.in'
14--- plugins/ini/ini.xml.in 2010-05-25 06:26:27 +0000
15+++ plugins/ini/ini.xml.in 1970-01-01 00:00:00 +0000
16@@ -1,13 +0,0 @@
17-<compiz>
18- <plugin name="ini">
19- <_short>Ini</_short>
20- <_long>Ini Flat File Backend</_long>
21- <deps>
22- <relation type="after">
23- <plugin>composite</plugin>
24- <plugin>opengl</plugin>
25- <plugin>decor</plugin>
26- </relation>
27- </deps>
28- </plugin>
29-</compiz>
30
31=== removed directory 'plugins/ini/src'
32=== removed file 'plugins/ini/src/ini.cpp'
33--- plugins/ini/src/ini.cpp 2012-01-18 16:26:45 +0000
34+++ plugins/ini/src/ini.cpp 1970-01-01 00:00:00 +0000
35@@ -1,614 +0,0 @@
36-/*
37- * Copyright © 2008 Danny Baumann
38- *
39- * Permission to use, copy, modify, distribute, and sell this software
40- * and its documentation for any purpose is hereby granted without
41- * fee, provided that the above copyright notice appear in all copies
42- * and that both that copyright notice and this permission notice
43- * appear in supporting documentation, and that the name of
44- * Danny Baumann not be used in advertising or publicity pertaining to
45- * distribution of the software without specific, written prior permission.
46- * Danny Baumann makes no representations about the suitability of this
47- * software for any purpose. It is provided "as is" without express or
48- * implied warranty.
49- *
50- * DANNY BAUMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
51- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
52- * NO EVENT SHALL DANNY BAUMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
53- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
54- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
55- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
56- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
57- *
58- * Author: Danny Baumann <dannybaumann@web.de>
59- *
60- * based on ini.c by :
61- * Mike Dransfield <mike@blueroot.co.uk>
62- */
63-
64-#include "ini.h"
65-
66-#include <sys/stat.h>
67-
68-#include <errno.h>
69-#include <boost/lexical_cast.hpp>
70-
71-COMPIZ_PLUGIN_20090315 (ini, IniPluginVTable)
72-
73-IniFile::IniFile (CompPlugin *p) :
74- plugin (p)
75-{
76-}
77-
78-IniFile::~IniFile ()
79-{
80- if (optionFile.is_open ())
81- optionFile.close ();
82-}
83-
84-bool
85-IniFile::open (bool write)
86-{
87- CompString homeDir;
88- std::ios_base::openmode mode;
89-
90- if (optionFile.is_open ())
91- optionFile.close ();
92-
93- homeDir = IniScreen::getHomeDir ();
94- if (homeDir.empty ())
95- return false;
96-
97- filePath = homeDir;
98- if (plugin->vTable->name () == "core")
99- filePath += "general";
100- else
101- filePath += plugin->vTable->name ();
102- filePath += FILE_SUFFIX;
103-
104- mode = write ? std::ios::out : std::ios::in;
105- optionFile.open (filePath.c_str (), mode);
106-
107- return !optionFile.fail ();
108-}
109-
110-void
111-IniFile::load ()
112-{
113- bool resave = false;
114-
115- if (!plugin)
116- return;
117-
118- CompOption::Vector& options = plugin->vTable->getOptions ();
119- if (options.empty ())
120- return;
121-
122- if (!open (false))
123- {
124- compLogMessage ("ini", CompLogLevelWarn,
125- "Could not open config for plugin %s - using defaults.",
126- plugin->vTable->name ().c_str ());
127-
128- save ();
129-
130- if (!open (false))
131- return;
132- }
133- else
134- {
135- CompString line, optionValue;
136- CompOption *option;
137- size_t pos;
138-
139- while (std::getline (optionFile, line))
140- {
141- pos = line.find_first_of ('=');
142- if (pos == CompString::npos)
143- continue;
144-
145- option = CompOption::findOption (options, line.substr (0, pos));
146- if (!option)
147- continue;
148-
149- optionValue = line.substr (pos + 1);
150- if (!stringToOption (option, optionValue))
151- resave = true;
152- }
153- }
154-
155- /* re-save whole file if we encountered invalid lines */
156- if (resave)
157- save ();
158-}
159-
160-void
161-IniFile::save ()
162-{
163- if (!plugin)
164- return;
165-
166- CompOption::Vector& options = plugin->vTable->getOptions ();
167- if (options.empty ())
168- return;
169-
170- if (!open (true))
171- {
172- IniScreen *is = IniScreen::get (screen);
173- CompString homeDir;
174-
175- homeDir = is->getHomeDir ();
176- is->createDir (homeDir);
177- is->updateDirectoryWatch (homeDir);
178- }
179-
180- if (!open (true))
181- {
182- compLogMessage ("ini", CompLogLevelError,
183- "Failed to write to config file %s, please "
184- "check if you have sufficient permissions.",
185- filePath.c_str ());
186- return;
187- }
188-
189- foreach (CompOption& option, options)
190- {
191- CompString optionValue;
192- bool valid;
193-
194- optionValue = optionToString (option, valid);
195- if (valid)
196- optionFile << option.name () << "=" << optionValue << std::endl;
197- }
198-}
199-
200-CompString
201-IniFile::optionValueToString (CompOption::Value &value,
202- CompOption::Type type)
203-{
204- CompString retval;
205-
206- switch (type) {
207- case CompOption::TypeBool:
208- retval = value.b () ? "true" : "false";
209- break;
210- case CompOption::TypeInt:
211- retval = boost::lexical_cast<CompString> (value.i ());
212- break;
213- case CompOption::TypeFloat:
214- retval = boost::lexical_cast<CompString> (value.f ());
215- break;
216- case CompOption::TypeString:
217- retval = value.s ();
218- break;
219- case CompOption::TypeColor:
220- retval = CompOption::colorToString (value.c ());
221- break;
222- case CompOption::TypeKey:
223- retval = value.action ().keyToString ();
224- break;
225- case CompOption::TypeButton:
226- retval = value.action ().buttonToString ();
227- break;
228- case CompOption::TypeEdge:
229- retval = value.action ().edgeMaskToString ();
230- break;
231- case CompOption::TypeBell:
232- retval = value.action ().bell () ? "true" : "false";
233- break;
234- case CompOption::TypeMatch:
235- retval = value.match ().toString ();
236- break;
237- default:
238- break;
239- }
240-
241- return retval;
242-}
243-
244-bool
245-IniFile::validItemType (CompOption::Type type)
246-{
247- switch (type) {
248- case CompOption::TypeBool:
249- case CompOption::TypeInt:
250- case CompOption::TypeFloat:
251- case CompOption::TypeString:
252- case CompOption::TypeColor:
253- case CompOption::TypeKey:
254- case CompOption::TypeButton:
255- case CompOption::TypeEdge:
256- case CompOption::TypeBell:
257- case CompOption::TypeMatch:
258- return true;
259- default:
260- break;
261- }
262-
263- return false;
264-}
265-
266-bool
267-IniFile::validListItemType (CompOption::Type type)
268-{
269- switch (type) {
270- case CompOption::TypeBool:
271- case CompOption::TypeInt:
272- case CompOption::TypeFloat:
273- case CompOption::TypeString:
274- case CompOption::TypeColor:
275- case CompOption::TypeMatch:
276- return true;
277- default:
278- break;
279- }
280-
281- return false;
282-}
283-
284-CompString
285-IniFile::optionToString (CompOption &option,
286- bool &valid)
287-{
288- CompString retval;
289- CompOption::Type type;
290-
291- valid = true;
292- type = option.type ();
293-
294- if (validItemType (type))
295- {
296- retval = optionValueToString (option.value (), option.type ());
297- }
298- else if (type == CompOption::TypeList)
299- {
300- type = option.value ().listType ();
301- if (validListItemType (type))
302- {
303- CompOption::Value::Vector& list = option.value ().list ();
304-
305- foreach (CompOption::Value& listOption, list)
306- {
307- retval += optionValueToString (listOption, type);
308- retval += ",";
309- }
310-
311- /* strip off dangling comma at the end */
312- if (!retval.empty ())
313- retval.erase (retval.length () - 1);
314- }
315- else
316- {
317- compLogMessage ("ini", CompLogLevelWarn,
318- "Unknown list option type %d on option %s.",
319- type, option.name ().c_str ());
320- valid = false;
321- }
322- }
323- else
324- {
325- compLogMessage ("ini", CompLogLevelWarn,
326- "Unknown option type %d found on option %s.",
327- type, option.name ().c_str ());
328- valid = false;
329- }
330-
331- return retval;
332-}
333-
334-bool
335-IniFile::stringToOptionValue (CompString &string,
336- CompOption::Type type,
337- CompOption::Value &value)
338-{
339- bool retval = true;
340-
341- switch (type) {
342- case CompOption::TypeBool:
343- if (string == "true")
344- value.set (true);
345- else if (string == "false")
346- value.set (false);
347- else
348- retval = false;
349- break;
350- case CompOption::TypeInt:
351- try
352- {
353- int intVal;
354- intVal = boost::lexical_cast<int> (string);
355- value.set (intVal);
356- }
357- catch (boost::bad_lexical_cast)
358- {
359- retval = false;
360- };
361- break;
362- case CompOption::TypeFloat:
363- try
364- {
365- float floatVal;
366- floatVal = boost::lexical_cast<float> (string);
367- value.set (floatVal);
368- }
369- catch (boost::bad_lexical_cast)
370- {
371- retval = false;
372- };
373- break;
374- case CompOption::TypeString:
375- value.set (string);
376- break;
377- case CompOption::TypeColor:
378- {
379- unsigned short c[4];
380- retval = CompOption::stringToColor (string, c);
381- if (retval)
382- value.set (c);
383- }
384- break;
385- case CompOption::TypeKey:
386- case CompOption::TypeButton:
387- case CompOption::TypeEdge:
388- case CompOption::TypeBell:
389- {
390- CompAction action;
391-
392- switch (type) {
393- case CompOption::TypeKey:
394- retval = action.keyFromString (string);
395- break;
396- case CompOption::TypeButton:
397- retval = action.buttonFromString (string);
398- break;
399- case CompOption::TypeEdge:
400- retval = action.edgeMaskFromString (string);
401- break;
402- case CompOption::TypeBell:
403- if (string == "true")
404- action.setBell (true);
405- else if (string == "false")
406- action.setBell (false);
407- else
408- retval = false;
409- break;
410- default:
411- break;
412- }
413-
414- if (retval)
415- value.set (action);
416- }
417- break;
418- case CompOption::TypeMatch:
419- {
420- CompMatch match (string);
421- value.set (match);
422- }
423- break;
424- default:
425- break;
426- }
427-
428- return retval;
429-}
430-
431-bool
432-IniFile::stringToOption (CompOption *option,
433- CompString &valueString)
434-{
435- CompOption::Value value;
436- bool valid = false;
437- CompOption::Type type = option->type ();
438-
439- if (validItemType (type))
440- {
441- valid = stringToOptionValue (valueString, option->type (), value);
442- }
443- else if (type == CompOption::TypeList)
444- {
445- type = option->value ().listType ();
446- if (validListItemType (type))
447- {
448- CompString listItem;
449- size_t delim, pos = 0;
450- CompOption::Value item;
451- CompOption::Value::Vector list;
452-
453- do
454- {
455- delim = valueString.find_first_of (',', pos);
456-
457- if (delim != CompString::npos)
458- listItem = valueString.substr (pos, delim - pos);
459- else
460- listItem = valueString.substr (pos);
461-
462- valid = stringToOptionValue (listItem, type, item);
463- if (valid)
464- list.push_back (item);
465-
466- pos = delim + 1;
467- }
468- while (delim != CompString::npos);
469-
470- value.set (type, list);
471- valid = true;
472- }
473- }
474-
475- if (valid)
476- screen->setOptionForPlugin (plugin->vTable->name ().c_str (),
477- option->name ().c_str (), value);
478-
479- return valid;
480-}
481-
482-void
483-IniScreen::fileChanged (const char *name)
484-{
485- CompString fileName, plugin;
486- unsigned int length;
487- CompPlugin *p;
488-
489- if (!name || strlen (name) <= strlen (FILE_SUFFIX))
490- return;
491-
492- fileName = name;
493-
494- length = fileName.length () - strlen (FILE_SUFFIX);
495- if (strcmp (fileName.c_str () + length, FILE_SUFFIX) != 0)
496- return;
497-
498- plugin = fileName.substr (0, length);
499- p = CompPlugin::find (plugin == "general" ? "core" : plugin.c_str ());
500- if (p)
501- {
502- IniFile ini (p);
503-
504- blockWrites = true;
505- ini.load ();
506- blockWrites = false;
507- }
508-}
509-
510-CompString
511-IniScreen::getHomeDir ()
512-{
513- char *home = getenv ("HOME");
514- CompString retval;
515-
516- if (home)
517- {
518- retval += home;
519- retval += "/";
520- retval += HOME_OPTIONDIR;
521- retval += "/";
522- }
523-
524- return retval;
525-}
526-
527-bool
528-IniScreen::createDir (const CompString& path)
529-{
530- size_t pos;
531-
532- if (mkdir (path.c_str (), 0700) == 0)
533- return true;
534-
535- /* did it already exist? */
536- if (errno == EEXIST)
537- return true;
538-
539- /* was parent present? if yes, fail */
540- if (errno != ENOENT)
541- return false;
542-
543- /* skip last character which may be a '/' */
544- pos = path.rfind ('/', path.size () - 2);
545- if (pos == CompString::npos)
546- return false;
547-
548- if (!createDir (path.substr (0, pos)))
549- return false;
550-
551- return (mkdir (path.c_str (), 0700) == 0);
552-}
553-
554-void
555-IniScreen::updateDirectoryWatch (const CompString& path)
556-{
557- int mask = NOTIFY_CREATE_MASK | NOTIFY_DELETE_MASK | NOTIFY_MODIFY_MASK;
558-
559- if (directoryWatchHandle)
560- screen->removeFileWatch (directoryWatchHandle);
561-
562- directoryWatchHandle =
563- screen->addFileWatch (path.c_str (), mask,
564- boost::bind (&IniScreen::fileChanged, this, _1));
565-}
566-
567-bool
568-IniScreen::setOptionForPlugin (const char *plugin,
569- const char *name,
570- CompOption::Value &v)
571-{
572- bool status = screen->setOptionForPlugin (plugin, name, v);
573-
574- if (status && !blockWrites)
575- {
576- CompPlugin *p;
577-
578- p = CompPlugin::find (plugin);
579- if (p)
580- {
581- CompOption *o;
582-
583- o = CompOption::findOption (p->vTable->getOptions (), name);
584- if (o && (o->value () != v))
585- {
586- IniFile ini (p);
587- ini.save ();
588- }
589- }
590- }
591-
592- return status;
593-}
594-
595-bool
596-IniScreen::initPluginForScreen (CompPlugin *p)
597-{
598- bool status = screen->initPluginForScreen (p);
599-
600- if (status)
601- {
602- IniFile ini (p);
603-
604- blockWrites = true;
605- ini.load ();
606- blockWrites = false;
607- }
608-
609- return status;
610-}
611-
612-IniScreen::IniScreen (CompScreen *screen) :
613- PluginClassHandler<IniScreen, CompScreen> (screen),
614- directoryWatchHandle (0),
615- blockWrites (false)
616-{
617- CompString homeDir;
618-
619- homeDir = getHomeDir ();
620- if (homeDir.empty () || !createDir (homeDir))
621- {
622- setFailed ();
623- return;
624- }
625-
626- updateDirectoryWatch (homeDir);
627-
628- IniFile ini (CompPlugin::find ("core"));
629- ini.load ();
630-
631- ScreenInterface::setHandler (screen, true);
632-}
633-
634-IniScreen::~IniScreen ()
635-{
636- if (directoryWatchHandle)
637- screen->removeFileWatch (directoryWatchHandle);
638-}
639-
640-bool
641-IniPluginVTable::init ()
642-{
643- if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
644- return false;
645-
646- return true;
647-}
648-
649-
650
651=== removed file 'plugins/ini/src/ini.h'
652--- plugins/ini/src/ini.h 2012-01-18 16:26:45 +0000
653+++ plugins/ini/src/ini.h 1970-01-01 00:00:00 +0000
654@@ -1,105 +0,0 @@
655-/*
656- * Copyright © 2008 Danny Baumann
657- *
658- * Permission to use, copy, modify, distribute, and sell this software
659- * and its documentation for any purpose is hereby granted without
660- * fee, provided that the above copyright notice appear in all copies
661- * and that both that copyright notice and this permission notice
662- * appear in supporting documentation, and that the name of
663- * Danny Baumann not be used in advertising or publicity pertaining to
664- * distribution of the software without specific, written prior permission.
665- * Danny Baumann makes no representations about the suitability of this
666- * software for any purpose. It is provided "as is" without express or
667- * implied warranty.
668- *
669- * DANNY BAUMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
670- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
671- * NO EVENT SHALL DANNY BAUMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
672- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
673- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
674- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
675- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
676- *
677- * Author: Danny Baumann <dannybaumann@web.de>
678- */
679-
680-#ifndef COMPIZ_INI_H
681-#define COMPIZ_INI_H
682-
683-#include <core/screen.h>
684-#include <core/pluginclasshandler.h>
685-
686-#include <fstream>
687-
688-#define HOME_OPTIONDIR ".compiz/options"
689-#define CORE_NAME "general"
690-#define FILE_SUFFIX ".conf"
691-
692-class IniScreen :
693- public ScreenInterface,
694- public PluginClassHandler<IniScreen, CompScreen>
695-{
696- public:
697- IniScreen (CompScreen *screen);
698- ~IniScreen ();
699-
700- bool initPluginForScreen (CompPlugin *p);
701- bool setOptionForPlugin (const char *plugin,
702- const char *name,
703- CompOption::Value &v);
704-
705- void updateDirectoryWatch (const CompString&);
706-
707- private:
708- CompFileWatchHandle directoryWatchHandle;
709-
710- void fileChanged (const char *name);
711-
712- bool blockWrites;
713-
714- public:
715- static CompString getHomeDir ();
716- static bool createDir (const CompString& path);
717-};
718-
719-class IniPluginVTable :
720- public CompPlugin::VTableForScreen<IniScreen>
721-{
722- public:
723-
724- bool init ();
725-};
726-
727-class IniFile
728-{
729- public:
730- IniFile (CompPlugin *p);
731- ~IniFile ();
732-
733- void load ();
734- void save ();
735-
736- private:
737- CompPlugin *plugin;
738- CompString filePath;
739-
740- std::fstream optionFile;
741-
742- bool open (bool write);
743-
744- CompString optionValueToString (CompOption::Value &value,
745- CompOption::Type type);
746- CompString optionToString (CompOption &option,
747- bool &valid);
748- bool stringToOption (CompOption *option,
749- CompString &valueString);
750- bool stringToOptionValue (CompString &string,
751- CompOption::Type type,
752- CompOption::Value &value);
753-
754- bool validItemType (CompOption::Type type);
755- bool validListItemType (CompOption::Type type);
756-};
757-
758-
759-#endif

Subscribers

People subscribed via source and target branches