~ubuntu-branches/ubuntu/hardy/codeblocks/hardy-backports

« back to all changes in this revision

Viewing changes to src/plugins/contrib/devpak_plugin/devpakupdater.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Casadevall
  • Date: 2008-07-17 04:39:23 UTC
  • Revision ID: james.westby@ubuntu.com-20080717043923-gmsy5cwkdjswghkm
Tags: upstream-8.02
ImportĀ upstreamĀ versionĀ 8.02

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
 
3
 * http://www.gnu.org/licenses/gpl-3.0.html
 
4
 *
 
5
 * $Revision: 4909 $
 
6
 * $Id: devpakupdater.cpp 4909 2008-02-27 13:15:26Z mortenmacfly $
 
7
 * $HeadURL: svn://svn.berlios.de/codeblocks/tags/8.02/src/plugins/contrib/devpak_plugin/devpakupdater.cpp $
 
8
 */
 
9
 
 
10
#include "devpakupdater.h"
 
11
#include "updatedlg.h"
 
12
#include "conf.h"
 
13
#include <manager.h>
 
14
#include <configmanager.h>
 
15
#include <compilerfactory.h>
 
16
#include <compiler.h>
 
17
#include <wx/msgdlg.h>
 
18
#include <wx/dirdlg.h>
 
19
#include <wx/intl.h>
 
20
 
 
21
// Register the plugin
 
22
namespace
 
23
{
 
24
    PluginRegistrant<DevPakUpdater> reg(_T("DevPakUpdater"));
 
25
};
 
26
 
 
27
DevPakUpdater::DevPakUpdater()
 
28
{
 
29
        //ctor
 
30
    if(!Manager::LoadResource(_T("devpakupdater.zip")))
 
31
    {
 
32
        NotifyMissingFile(_T("devpakupdater.zip"));
 
33
    }
 
34
    g_MasterPath = Manager::Get()->GetConfigManager(_T("devpak_plugin"))->Read(_T("/master_path"));
 
35
}
 
36
 
 
37
DevPakUpdater::~DevPakUpdater()
 
38
{
 
39
        //dtor
 
40
}
 
41
 
 
42
void DevPakUpdater::OnAttach()
 
43
{
 
44
}
 
45
 
 
46
void DevPakUpdater::OnRelease(bool appShutDown)
 
47
{
 
48
}
 
49
 
 
50
bool DevPakUpdater::ConfigurationValid()
 
51
{
 
52
    // let's make sure we have a valid configuration
 
53
    if (g_MasterPath.IsEmpty() || !wxDirExists(g_MasterPath))
 
54
    {
 
55
        if (wxMessageBox(_("The Dev-C++ DevPak Plugin is not configured yet.\nDo you want to configure it now?"), _("Question"), wxICON_QUESTION | wxYES_NO) == wxNO)
 
56
            return false;
 
57
        if (Configure() != 0)
 
58
            return false;
 
59
        // ask to add in compiler paths
 
60
        if (wxMessageBox(_("Do you want to add this path to the compiler's search dirs?\n"
 
61
                        "(needed to be able to actually compile anything)"),
 
62
                        _("Question"), wxICON_QUESTION | wxYES_NO) == wxYES)
 
63
        {
 
64
            Compiler* compiler = CompilerFactory::GetCompiler(0); // GCC is always first compiler
 
65
            if (!compiler)
 
66
            {
 
67
                wxMessageBox(_("Invalid compiler!?!"), _("Error"), wxICON_ERROR);
 
68
                return true;
 
69
            }
 
70
            compiler->AddIncludeDir(g_MasterPath + wxFILE_SEP_PATH + _T("include"));
 
71
            compiler->AddLibDir(g_MasterPath + wxFILE_SEP_PATH + _T("lib"));
 
72
        }
 
73
    }
 
74
    return true;
 
75
}
 
76
 
 
77
int DevPakUpdater::Configure()
 
78
{
 
79
    if (g_MasterPath.IsEmpty())
 
80
        g_MasterPath = ConfigManager::GetConfigFolder() + wxFILE_SEP_PATH + _T("DevPaks");
 
81
        wxString dir = wxDirSelector(_("Please select the path where DevPaks will be downloaded and installed:"),
 
82
                                g_MasterPath);
 
83
    if (!dir.IsEmpty())
 
84
    {
 
85
        g_MasterPath = dir;
 
86
        if (!ConfigurationValid())
 
87
        {
 
88
            g_MasterPath.Clear();
 
89
            return -1;
 
90
        }
 
91
        Manager::Get()->GetConfigManager(_T("devpak_plugin"))->Write(_T("/master_path"), g_MasterPath);
 
92
        return 0;
 
93
    }
 
94
    return -1;
 
95
}
 
96
 
 
97
int DevPakUpdater::Execute()
 
98
{
 
99
    if (!ConfigurationValid())
 
100
        return -1;
 
101
    UpdateDlg dlg(Manager::Get()->GetAppWindow());
 
102
    dlg.ShowModal();
 
103
        return 0;
 
104
}