libyui  3.0.10
 All Classes Functions Variables Enumerations Friends
YExternalWidgets.cc
1 /*
2  Copyright (C) 2013 Angelo Naselli <anaselli at linux dot it>
3 
4  This file is part of libyui project
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as
8  published by the Free Software Foundation; either version 2.1 of the
9  License, or (at your option) version 3.0 of the License. This library
10  is distributed in the hope that it will be useful, but WITHOUT ANY
11  WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  License for more details. You should have received a copy of the GNU
14  Lesser General Public License along with this library; if not, write
15  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
16  Floor, Boston, MA 02110-1301 USA
17 */
18 #define YUILogComponent "we"
19 #include "YUILog.h"
20 
21 #include "YUI.h"
22 #include "YUIException.h"
23 #include "YExternalWidgets.h"
24 
25 YExternalWidgets * YExternalWidgets::_externalWidgets = 0;
26 
27 
29 {
30  if (!YUI::ui())
31  YUI_THROW( YUIException( "UI must be initialized first" ) );
32 
33  yuiMilestone() << "Creating Libyui Widget Extension object" << std::endl;
34 
35  _externalWidgets = this;
36 }
37 
39 {
40  _externalWidgets = 0;
41 }
42 
44 {
45  // we cannot ensure to have loaded it as for YUI, because the name
46  // of the plugin is user dependent
47  return _externalWidgets;
48 }
49 
51 {
52  static YExternalWidgetFactory * factory = 0;
53 
54  if (!YUI::ui())
55  YUI_THROW( YUIException( "UI must be initialized first" ) );
56 
57  if (!_externalWidgets)
58  YUI_THROW( YUIException( "WE (Widget Extension) must be initialized first" ) );
59 
60  if ( !factory )
62 
63  YUI_CHECK_PTR( factory );
64 
65  return factory;
66 }
67 
68 
69 
70 
71 /**
72  * Helper class to make sure the WE is properly shut down.
73  **/
75 {
76 public:
78 
79  /**
80  * Destructor.
81  *
82  * If there still is a WE, it will be deleted.
83  * If there is none, this will do nothing.
84  **/
86 };
87 
88 
90 {
91  if ( YExternalWidgets::_externalWidgets )
92  {
93  yuiMilestone() << "Shutting down WE" << std::endl;
94  delete YExternalWidgets::_externalWidgets;
95 
96  YExternalWidgets::_externalWidgets = 0;
97  }
98 }
99 
100 
101 /**
102  * Static YExternalWidgetsTerminator instance: It will make sure the WE is deleted in its
103  * global destructor. If the WE is already destroyed, it will do nothing. If
104  * there still is a WE object, it will be deleted.
105  *
106  * This is particularly important for the NCurses WE so the terminal settings
107  * are properly restored.
108  **/
109 static YExternalWidgetsTerminator weTerminator;
110 
virtual YExternalWidgetFactory * createExternalWidgetFactory()=0
virtual ~YExternalWidgets()
static YExternalWidgets * externalWidgets()
static YExternalWidgetFactory * externalWidgetFactory()
static YUI * ui()
Definition: YUI.cc:118