widgetcreator.cpp
author jake
Wed, 02 Jun 2010 13:22:05 +0300
changeset 0 b856a9924bbc
child 6 ac3b45850c50
permissions -rw-r--r--
initial contribution
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
b856a9924bbc initial contribution
jake
parents:
diff changeset
     1
#include "widgetcreator.h"
b856a9924bbc initial contribution
jake
parents:
diff changeset
     2
#include <QDir>
b856a9924bbc initial contribution
jake
parents:
diff changeset
     3
#include <QTextStream>
b856a9924bbc initial contribution
jake
parents:
diff changeset
     4
#include <QCheckBox>
b856a9924bbc initial contribution
jake
parents:
diff changeset
     5
b856a9924bbc initial contribution
jake
parents:
diff changeset
     6
WidgetCreator::WidgetCreator(MainWindow& aUi, QObject *parent ) :
b856a9924bbc initial contribution
jake
parents:
diff changeset
     7
    QObject(parent), iUi( aUi )
b856a9924bbc initial contribution
jake
parents:
diff changeset
     8
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
     9
    generateFolders();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    10
    generateBuildFile();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    11
    generateHSPSManifest();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    12
    generateEmptyDat();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    13
    generateHSPSConf();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    14
    generateXml();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    15
    generateCss();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    16
    generateDat();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    17
    generateDtd();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    18
    generatePkg();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    19
    generateBur();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    20
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    21
b856a9924bbc initial contribution
jake
parents:
diff changeset
    22
b856a9924bbc initial contribution
jake
parents:
diff changeset
    23
b856a9924bbc initial contribution
jake
parents:
diff changeset
    24
QString WidgetCreator::widgetName()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    25
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    26
    return iUi.widgetName();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    27
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    28
b856a9924bbc initial contribution
jake
parents:
diff changeset
    29
QString WidgetCreator::widgetUid()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    30
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    31
    return iUi.widgetUid();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    32
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    33
b856a9924bbc initial contribution
jake
parents:
diff changeset
    34
QString WidgetCreator::widgetLayout()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    35
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    36
    return iUi.widgetLayout();
b856a9924bbc initial contribution
jake
parents:
diff changeset
    37
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    38
b856a9924bbc initial contribution
jake
parents:
diff changeset
    39
void WidgetCreator::generateFolders()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    40
{    
b856a9924bbc initial contribution
jake
parents:
diff changeset
    41
    QDir dir;
b856a9924bbc initial contribution
jake
parents:
diff changeset
    42
    dir.mkpath( widgetName() + "/widget");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    43
    dir.setPath( widgetName() + "/widget" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    44
    dir.mkpath( "group" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    45
    dir.mkpath( "hsps/00" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    46
    dir.mkpath( "xuikon/00" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    47
    dir.mkpath( "sis" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    48
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    49
b856a9924bbc initial contribution
jake
parents:
diff changeset
    50
void WidgetCreator::generateBuildFile()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    51
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    52
    iUi.replaceData("data/" + widgetLayout() +"/group/bld.inf", widgetName() + "/widget/group/bld.inf", 1);
b856a9924bbc initial contribution
jake
parents:
diff changeset
    53
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    54
b856a9924bbc initial contribution
jake
parents:
diff changeset
    55
void WidgetCreator::generateHSPSManifest()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    56
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    57
    iUi.replaceData("data/" + widgetLayout() +"/hsps/00/manifest.dat",
b856a9924bbc initial contribution
jake
parents:
diff changeset
    58
                widgetName() + "/widget/hsps/00/manifest.dat");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    59
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    60
b856a9924bbc initial contribution
jake
parents:
diff changeset
    61
void WidgetCreator::generateHSPSConf()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    62
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    63
    iUi.replaceData( "data/" + widgetLayout() +"/hsps/00/widgetconfiguration.xml",
b856a9924bbc initial contribution
jake
parents:
diff changeset
    64
                 widgetName() + "/widget/hsps/00/widgetconfiguration.xml" );
b856a9924bbc initial contribution
jake
parents:
diff changeset
    65
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    66
b856a9924bbc initial contribution
jake
parents:
diff changeset
    67
void WidgetCreator::generateEmptyDat()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    68
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    69
    QDir dir;
b856a9924bbc initial contribution
jake
parents:
diff changeset
    70
    dir.setPath( widgetName() + "/widget/hsps/00");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    71
    QFile file(dir.filePath("empty.dat"));
b856a9924bbc initial contribution
jake
parents:
diff changeset
    72
    if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
b856a9924bbc initial contribution
jake
parents:
diff changeset
    73
        return;
b856a9924bbc initial contribution
jake
parents:
diff changeset
    74
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
    75
b856a9924bbc initial contribution
jake
parents:
diff changeset
    76
void WidgetCreator::generateXml()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    77
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    78
    if( iUi.rendererCheckBox().isChecked())
b856a9924bbc initial contribution
jake
parents:
diff changeset
    79
    {
b856a9924bbc initial contribution
jake
parents:
diff changeset
    80
        iUi.replaceData( "data/" + widgetLayout() +"/xuikon/00/replacerenderer.xml",
b856a9924bbc initial contribution
jake
parents:
diff changeset
    81
             widgetName() + "/widget/xuikon/00/" + iUi.widgetName() +  ".xml");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    82
    }
b856a9924bbc initial contribution
jake
parents:
diff changeset
    83
    else
b856a9924bbc initial contribution
jake
parents:
diff changeset
    84
    {
b856a9924bbc initial contribution
jake
parents:
diff changeset
    85
        iUi.replaceData( "data/" + widgetLayout() +"/xuikon/00/replace.xml",
b856a9924bbc initial contribution
jake
parents:
diff changeset
    86
             widgetName() + "/widget/xuikon/00/" + iUi.widgetName() +  ".xml");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    87
    }
b856a9924bbc initial contribution
jake
parents:
diff changeset
    88
b856a9924bbc initial contribution
jake
parents:
diff changeset
    89
}  
b856a9924bbc initial contribution
jake
parents:
diff changeset
    90
        
b856a9924bbc initial contribution
jake
parents:
diff changeset
    91
void WidgetCreator::generateCss()
b856a9924bbc initial contribution
jake
parents:
diff changeset
    92
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
    93
    if( iUi.rendererCheckBox().isChecked())
b856a9924bbc initial contribution
jake
parents:
diff changeset
    94
    {
b856a9924bbc initial contribution
jake
parents:
diff changeset
    95
        iUi.replaceData( "data/" + widgetLayout() +"/xuikon/00/replacerenderer.css",
b856a9924bbc initial contribution
jake
parents:
diff changeset
    96
             widgetName() + "/widget/xuikon/00/" + iUi.widgetName() +  ".css");
b856a9924bbc initial contribution
jake
parents:
diff changeset
    97
    }
b856a9924bbc initial contribution
jake
parents:
diff changeset
    98
    else
b856a9924bbc initial contribution
jake
parents:
diff changeset
    99
    {
b856a9924bbc initial contribution
jake
parents:
diff changeset
   100
        iUi.replaceData( "data/" + widgetLayout() +"/xuikon/00/replace.css",
b856a9924bbc initial contribution
jake
parents:
diff changeset
   101
             widgetName() + "/widget/xuikon/00/" + iUi.widgetName() +  ".css");
b856a9924bbc initial contribution
jake
parents:
diff changeset
   102
    }
b856a9924bbc initial contribution
jake
parents:
diff changeset
   103
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
   104
b856a9924bbc initial contribution
jake
parents:
diff changeset
   105
void WidgetCreator::generateDat()
b856a9924bbc initial contribution
jake
parents:
diff changeset
   106
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
   107
    iUi.replaceData("data/" + widgetLayout() +"/xuikon/00/replace.dat",
b856a9924bbc initial contribution
jake
parents:
diff changeset
   108
                widgetName() + "/widget/xuikon/00/" + widgetName() + "_" + iUi.widgetUidNoHex() + ".dat");
b856a9924bbc initial contribution
jake
parents:
diff changeset
   109
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
   110
b856a9924bbc initial contribution
jake
parents:
diff changeset
   111
void WidgetCreator::generateDtd()
b856a9924bbc initial contribution
jake
parents:
diff changeset
   112
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
   113
    QDir dir;
b856a9924bbc initial contribution
jake
parents:
diff changeset
   114
    dir.setPath( widgetName() + "/widget/xuikon/00");
b856a9924bbc initial contribution
jake
parents:
diff changeset
   115
    QFile file(dir.filePath(widgetName()+".dtd"));
b856a9924bbc initial contribution
jake
parents:
diff changeset
   116
    if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
b856a9924bbc initial contribution
jake
parents:
diff changeset
   117
        return;
b856a9924bbc initial contribution
jake
parents:
diff changeset
   118
b856a9924bbc initial contribution
jake
parents:
diff changeset
   119
}
b856a9924bbc initial contribution
jake
parents:
diff changeset
   120
b856a9924bbc initial contribution
jake
parents:
diff changeset
   121
void WidgetCreator::generatePkg()
b856a9924bbc initial contribution
jake
parents:
diff changeset
   122
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
   123
    iUi.replaceData("data/" + widgetLayout() +"/sis/replace.pkg",
b856a9924bbc initial contribution
jake
parents:
diff changeset
   124
                widgetName() + "/widget/sis/"+ widgetName() + ".pkg", 1); // 1 =no hex uid used
b856a9924bbc initial contribution
jake
parents:
diff changeset
   125
   }
b856a9924bbc initial contribution
jake
parents:
diff changeset
   126
b856a9924bbc initial contribution
jake
parents:
diff changeset
   127
void WidgetCreator::generateBur()
b856a9924bbc initial contribution
jake
parents:
diff changeset
   128
{
b856a9924bbc initial contribution
jake
parents:
diff changeset
   129
    QDir dir;
b856a9924bbc initial contribution
jake
parents:
diff changeset
   130
    dir.setPath( widgetName() + "/widget/sis");
b856a9924bbc initial contribution
jake
parents:
diff changeset
   131
    QFile file(dir.filePath("backup_registration.xml"));
b856a9924bbc initial contribution
jake
parents:
diff changeset
   132
    if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
b856a9924bbc initial contribution
jake
parents:
diff changeset
   133
        return;
b856a9924bbc initial contribution
jake
parents:
diff changeset
   134
b856a9924bbc initial contribution
jake
parents:
diff changeset
   135
    QTextStream out(&file);
b856a9924bbc initial contribution
jake
parents:
diff changeset
   136
b856a9924bbc initial contribution
jake
parents:
diff changeset
   137
    out << "<?xml version=\"1.0\" standalone=\"yes\"?>\n"
b856a9924bbc initial contribution
jake
parents:
diff changeset
   138
    << "<backup_registration>\n"
b856a9924bbc initial contribution
jake
parents:
diff changeset
   139
    << "<system_backup/>\n"
b856a9924bbc initial contribution
jake
parents:
diff changeset
   140
    << "<restore requires_reboot = \"no\"/>\n"
b856a9924bbc initial contribution
jake
parents:
diff changeset
   141
    << "</backup_registration>\n";
b856a9924bbc initial contribution
jake
parents:
diff changeset
   142
}