summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings2/resources.h
blob: 634cd3902200244ef47d72a0deea5aabe88cb163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef __RESOURCES__H
#define __RESOURCES__H

#include <qstring.h>
#include <qdict.h>
#include <qmap.h>
#include <qlist.h>
#include "netnode.h"
#include "systemfile.h"
#include "system.h"

class QLibrary;
class QPixmap;
class ANetNode;
class ANetNodeInstance;

typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );

typedef struct NetNode_S {
        ANetNode * NetNode;
        QLibrary * TheLibrary;
        long NodeCountInLib;
} NetNode_t;

class CurrentQPEUser {

public :
        CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}

        inline bool known( void )
          { return ! HomeDir.isEmpty() && ! UserName.isEmpty(); }

        QString        UserName;
        QString        HomeDir;
        int            Uid;
        int            Gid;
        QArray<char *> EnvList;
};

typedef QDict<NetNode_t> Name2NetNode_t;
typedef QDict<ANetNodeInstance > Name2Instance_t;
typedef QDict<NodeCollection> Name2Connection_t;
typedef QDict<SystemFile> Name2SystemFile_t;

class TheNSResources {

public :

    TheNSResources( void );
    ~TheNSResources( );

    // give busy feedback
    void busy( bool B );

    System & system()
      { return *TheSystem; }

    int assignConnectionNumber(void);
    QPixmap getPixmap( const QString & Name );

    Name2NetNode_t & netNodes( void ) 
      { return AllNodeTypes; }
    bool netNodeExists( const QString & X )
      { return AllNodeTypes.find(X)!=0; }
    ANetNode * findNetNode( const QString & N )
      { NetNode_t * NNT = AllNodeTypes.find(N);
        return (NNT) ? NNT->NetNode : 0;
      }

    // define new plugin (=node)
    void addNodeType( const QString & ID,
                      const QString & LongName,
                      const QString & Description );

    Name2SystemFile_t & systemFiles( void )
      { return SystemFiles; }
    void addSystemFile( const QString & ID, 
                        const QString & P,
                        bool KDI );

    ANetNodeInstance * createNodeInstance( const QString & S )
      { ANetNodeInstance * NNI = 0;
        NetNode_t * NNT = AllNodeTypes[S];
        if( ! NNT ) {
          return 0;
        }
        NNI = NNT->NetNode->createInstance();
        NNI->initialize();
        return NNI;
      }

    Name2Instance_t & netNodeInstances( void ) 
      { return AllNodes; }
    void addNodeInstance( ANetNodeInstance * I )
      { AllNodes.insert( I->name(), I ); }
    void removeNodeInstance( const QString & N )
      { AllNodes.remove( N );}
    ANetNodeInstance * findNodeInstance( const QString & S )
      { return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }

    const QString & netNode2Name( const char * Type );
    const QString & netNode2Description( const char * Type );

    void addConnection( NodeCollection * NC );
    void removeConnection( const QString & N );
    NodeCollection * findConnection( const QString & N );
    NodeCollection * getConnection( int nr );
    Name2Connection_t & connections( void )
      { return ConnectionsMap; }

    inline bool userKnown( void )
      { return CurrentUser.known(); }
    CurrentQPEUser & currentUser( void )
      { return CurrentUser; }

private :

    void detectCurrentUser( void );
    QString tr( const char * path );
    void findAvailableNetNodes( const QString &path );
    bool loadNetNode(
         const QString &pluginFileName,
         const QString &resolveString = "create_plugin");

    QMap< QString, QString>   NodeTypeNameMap;
    QMap< QString, QString>   NodeTypeDescriptionMap;
    Name2Connection_t ConnectionsMap;
    System * TheSystem;
    Name2SystemFile_t SystemFiles;

    // all node type classes 
    Name2NetNode_t      AllNodeTypes;

    // all nodes
    Name2Instance_t     AllNodes;

    CurrentQPEUser      CurrentUser;
};

extern TheNSResources * _NSResources;
#define NSResources _NSResources

#endif