~george-edison55/juju-qt-gui/trunk

« back to all changes in this revision

Viewing changes to src/CEnvironmentsDialog.cpp

  • Committer: Nathan Osman
  • Date: 2011-12-05 20:10:09 UTC
  • Revision ID: admin@quickmediasolutions.com-20111205201009-qiwk6acmwd5itnlk
Added type-specific configuration pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
// C++ includes
29
29
#include <fstream>
30
30
 
 
31
// Juju GUI includes
 
32
#include <CEC2EnvironmentWidget.h>
 
33
#include <CGenericEnvironmentWidget.h>
 
34
#include <CLocalEnvironmentWidget.h>
 
35
 
31
36
CEnvironmentsDialog::CEnvironmentsDialog(QWidget * parent)
32
37
    : QDialog(parent), ui(new Ui::CEnvironmentsDialog)
33
38
{
34
39
    ui->setupUi(this);
35
40
 
 
41
    ui->Environments->setBaseSize(100, 100);
 
42
 
36
43
    // Determine the absolute filename of the config file
37
44
    QString config_file = QDir::home().absoluteFilePath(".juju/environments.yaml");
38
45
    m_config_file = config_file.toUtf8().data();
86
93
 
87
94
/// Called when the current selection in the environments listbox changes.
88
95
/**
89
 
  * \param the currently selected item
90
 
  * \param the previously selected item
 
96
  * \param current the currently selected item
91
97
  */
92
 
void CEnvironmentsDialog::OnItemChanged(QListWidgetItem * current, QListWidgetItem * previous)
 
98
void CEnvironmentsDialog::OnItemChanged(QListWidgetItem * current, QListWidgetItem *)
93
99
{
94
 
    //...
 
100
    // Get the name of the environment we are switching to
 
101
    QString env_name = current->data(Qt::UserRole).toString();
 
102
 
 
103
    // Retrieve the type of that environment
 
104
    EnvironmentMap::const_iterator i = m_environments.find(env_name);
 
105
    if(i != m_environments.end())
 
106
    {
 
107
        // Delete the old widget
 
108
        delete ui->EnvironmentWidget;
 
109
 
 
110
        if(i.value()["type"] == "local")
 
111
            ui->Layout->addWidget(ui->EnvironmentWidget = new CLocalEnvironmentWidget(this));
 
112
        else if(i.value()["type"] == "ec2")
 
113
            ui->Layout->addWidget(ui->EnvironmentWidget = new CEC2EnvironmentWidget(this));
 
114
        else
 
115
            ui->Layout->addWidget(ui->EnvironmentWidget = new CGenericEnvironmentWidget(this));
 
116
    }
95
117
}
96
118
 
97
119
/// Attempts to load the configuration from the file in the user's home directory.
222
244
void CEnvironmentsDialog::PopulateListbox()
223
245
{
224
246
    for(EnvironmentMap::const_iterator i = m_environments.begin(); i != m_environments.end(); ++i)
225
 
        ui->Environments->addItem(i.key());
 
247
    {
 
248
        QListWidgetItem * item = new QListWidgetItem(ui->Environments);
 
249
        item->setText(i.key());
 
250
        item->setData(Qt::UserRole ,i.key());
 
251
 
 
252
        ui->Environments->addItem(item);
 
253
    }
226
254
 
227
255
    // Set the default item
228
256
    if(m_environments.size())