summaryrefslogtreecommitdiffstats
path: root/quanta/utility/newstuff.cpp
blob: a00e9c7512c94142ea1b53ca97a166d0ffe7cff6 (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
144
/***************************************************************************
                          newstuff.cpp  -  description
                             -------------------
    begin                : Tue Jun 22 12:19:55 2004
    copyright          : (C) 2004 by Andras Mantia <[email protected]>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; version 2 of the License.               *
 *                                                                         *
 ***************************************************************************/
 //qt includes
#include <tqfileinfo.h>

//kde includes
#include <tdeglobal.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kstandarddirs.h>
#include <ktar.h>

//app includes
#include "newstuff.h"
#include "dtds.h"
#include "resource.h"
#include "quantacommon.h"
#include "qextfileinfo.h"

void QNewDTEPStuff::installResource()
{
    bool ok = true;
    KTar tar(m_tarName, "application/x-gzip");
    if (tar.open(IO_ReadOnly))
    {
        const KArchiveDirectory *directory = tar.directory();
        TQString dtepDir =TDEGlobal::dirs()->saveLocation("data") + resourceDir + "dtep/";
        TQString dtdName = (*directory->entries().at(0));
        if (dtdName.isEmpty())
        {
          ok = false;
        } else
        {
          directory->copyTo(dtepDir, true);
          DTDs::ref()->slotLoadDTEP(dtepDir + dtdName, false);
        }
        tar.close();
    } else
        ok = false;
    if (!ok)
        KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded DTEP tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("DTEP Installation Error"));
}

QNewToolbarStuff::QNewToolbarStuff(const TQString &type,  TQWidget *parentWidget)
  :TDENewStuffSecure(type, parentWidget)
{
  connect(this, TQT_SIGNAL(loadToolbarFile(const KURL&)), parentWidget, TQT_SLOT(slotLoadToolbarFile(const KURL&)));
}


void QNewToolbarStuff::installResource()
{
    KURL destURL = KURL::fromPathOrURL(TDEGlobal::dirs()->saveLocation("data") + resourceDir + "toolbars/" + TQFileInfo(m_tarName).fileName());
    bool ok = true;
    if (QuantaCommon::checkOverwrite(destURL, parentWidget()))
    {
        if (!QExtFileInfo::copy(KURL::fromPathOrURL(m_tarName), destURL, -1, true, false, parentWidget()))
          ok = false;
        else
        {
           if (KMessageBox::questionYesNo(parentWidget(), i18n("Do you want to load the newly downloaded toolbar?"), i18n("Load Toolbar"), i18n("Load"), KStdGuiItem::cancel()) == KMessageBox::Yes)
           {
              emit loadToolbarFile(destURL);
           }
        }
        if (!ok)
            KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded toolbar tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Toolbar Installation Error"));
     }
}

QNewTemplateStuff::QNewTemplateStuff(const TQString &type,  TQWidget *parentWidget)
  :TDENewStuffSecure(type, parentWidget)
{
  connect(this, TQT_SIGNAL(openFile(const KURL&)), parentWidget, TQT_SLOT(slotFileOpen(const KURL&)));
}


void QNewTemplateStuff::installResource()
{
    KURL destURL = KURL::fromPathOrURL(TDEGlobal::dirs()->saveLocation("data") + resourceDir + "templates/" + TQFileInfo(m_tarName).fileName());
    bool ok = true;
    if (QuantaCommon::checkOverwrite(destURL, parentWidget()))
    {
        if (!QExtFileInfo::copy(KURL::fromPathOrURL(m_tarName), destURL, -1, true, false, parentWidget()))
          ok = false;
        else
        {
           if (KMessageBox::questionYesNo(parentWidget(), i18n("Do you want to open the newly downloaded template?"), i18n("Open Template"), KStdGuiItem::open(), KStdGuiItem::cancel()) == KMessageBox::Yes)
           {
              emit openFile(destURL);
           }
        }
        if (!ok)
            KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded template file."), i18n("Template Installation Error"));
     }
}

void QNewScriptStuff::installResource()
{
    bool ok = true;
    KTar tar(m_tarName, "application/x-gzip");
    if (tar.open(IO_ReadOnly))
    {
        const KArchiveDirectory *directory = tar.directory();
        TQString scriptsDir =TDEGlobal::dirs()->saveLocation("data") + resourceDir + "scripts/";
        directory->copyTo(scriptsDir, true);
        tar.close();
    } else
        ok = false;

    if (!ok)
        KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded script tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Script Installation Error"));
}

void QNewDocStuff::installResource()
{
  bool ok = true;
  KTar tar(m_tarName, "application/x-gzip");
  if (tar.open(IO_ReadOnly))
  {
    const KArchiveDirectory *directory = tar.directory();
    TQString docDir =TDEGlobal::dirs()->saveLocation("data") + resourceDir + "doc/";
    directory->copyTo(docDir, true);
    tar.close();
  } else
    ok = false;

    if (!ok)
      KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded script tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Documentation Installation Error"));
}

#include "newstuff.moc"