Settings::Settings( Core *coreSettings, QWidget *parent ) : QDialog( parent ), updateAccountsOnExit( false ), core( coreSettings ), pluginManagerTab(0) { // Sorry, but this has to be here and not in Qtwitter::Qtwitter() for the core to be aware // of the signal emitted in Settings::Settings() connect( this, SIGNAL(createAccounts(QWidget*)), core, SLOT(createAccounts(QWidget*)) ); ui.setupUi( this ); themes.insert( Themes::STYLESHEET_COCOA.first, Themes::STYLESHEET_COCOA.second); themes.insert( Themes::STYLESHEET_GRAY.first, Themes::STYLESHEET_GRAY.second); themes.insert( Themes::STYLESHEET_GREEN.first, Themes::STYLESHEET_GREEN.second); themes.insert( Themes::STYLESHEET_PURPLE.first, Themes::STYLESHEET_PURPLE.second); themes.insert( Themes::STYLESHEET_SKY.first, Themes::STYLESHEET_SKY.second); for (int i = 0; i < themes.keys().size(); ++i ) { ui.colorBox->addItem( themes.keys()[i] ); } createLanguageMenu(); #ifdef Q_WS_X11 QHBoxLayout *hlayout = new QHBoxLayout; useCustomBrowserCheckBox = new QCheckBox( tr( "Use custom web browser" ), ui.networkTab ); selectBrowserEdit = new QLineEdit( ui.networkTab ); selectBrowserButton = new QPushButton( tr( "Browse" ), ui.networkTab ); hlayout->addWidget(selectBrowserEdit); hlayout->addWidget(selectBrowserButton); ui.verticalLayout_2->addWidget(useCustomBrowserCheckBox); ui.verticalLayout_2->addLayout(hlayout); selectBrowserEdit->setEnabled( false ); selectBrowserButton->setEnabled( false ); connect( useCustomBrowserCheckBox, SIGNAL(toggled(bool)), selectBrowserEdit, SLOT(setEnabled(bool)) ); connect( useCustomBrowserCheckBox, SIGNAL(toggled(bool)), selectBrowserButton, SLOT(setEnabled(bool)) ); connect( selectBrowserButton, SIGNAL(clicked()), this, SLOT(setBrowser()) ); #endif connect( ui.languageCombo, SIGNAL( currentIndexChanged( int )), this, SLOT( switchLanguage( int ) ) ); connect( ui.colorBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeTheme(QString)) ); connect( ui.checkNowButton, SIGNAL(clicked()), this, SLOT(checkForUpdate()) ); ui.portEdit->setValidator( new QIntValidator( 1, 65535, this ) ); emit createAccounts( ui.widget ); // loadConfig(); }
bool MyMoneyTemplate::importTemplate(void(*callback)(int, int, const QString&)) { m_progressCallback = callback; bool rc = !m_accounts.isNull(); MyMoneyFile* file = MyMoneyFile::instance(); signalProgress(0, m_doc.elementsByTagName("account").count(), i18n("Loading template %1", m_source.url())); m_accountsRead = 0; while (rc == true && !m_accounts.isNull() && m_accounts.isElement()) { QDomElement childElement = m_accounts.toElement(); if (childElement.tagName() == "account" && childElement.attribute("name").isEmpty()) { ++m_accountsRead; MyMoneyAccount parent; switch (childElement.attribute("type").toUInt()) { case MyMoneyAccount::Asset: parent = file->asset(); break; case MyMoneyAccount::Liability: parent = file->liability(); break; case MyMoneyAccount::Income: parent = file->income(); break; case MyMoneyAccount::Expense: parent = file->expense(); break; case MyMoneyAccount::Equity: parent = file->equity(); break; default: KMessageBox::error(KMyMoneyUtils::mainWindow(), i18n("<p>Invalid top-level account type <b>%1</b> in template file <b>%2</b></p>", childElement.attribute("type"), m_source.prettyUrl())); rc = false; } if (rc == true) { rc = createAccounts(parent, childElement.firstChild()); } } else { rc = false; } m_accounts = m_accounts.nextSibling(); } signalProgress(-1, -1); return rc; }
bool MyMoneyTemplate::createAccounts(MyMoneyAccount& parent, QDomNode account) { bool rc = true; while (rc == true && !account.isNull()) { MyMoneyAccount acc; if (account.isElement()) { QDomElement accountElement = account.toElement(); if (accountElement.tagName() == "account") { signalProgress(++m_accountsRead, 0); QList<MyMoneyAccount> subAccountList; QList<MyMoneyAccount>::ConstIterator it; it = subAccountList.constEnd(); if (!parent.accountList().isEmpty()) { MyMoneyFile::instance()->accountList(subAccountList, parent.accountList()); for (it = subAccountList.constBegin(); it != subAccountList.constEnd(); ++it) { if ((*it).name() == accountElement.attribute("name")) { acc = *it; break; } } } if (it == subAccountList.constEnd()) { // not found, we need to create it acc.setName(accountElement.attribute("name")); acc.setAccountType(static_cast<MyMoneyAccount::_accountTypeE>(accountElement.attribute("type").toUInt())); setFlags(acc, account.firstChild()); try { MyMoneyFile::instance()->addAccount(acc, parent); } catch (const MyMoneyException &) { } } createAccounts(acc, account.firstChild()); } } account = account.nextSibling(); } return rc; }