void accountmanagerdialog::on_editButton_clicked()
{
    QList<QListWidgetItem*> selected = ui->listWidget->selectedItems();
    if(selected.isEmpty())
        return;
    QListWidgetItem *thisOne = selected.first();
    Account *acc = getAccount(thisOne);

    AccountDialog *accDiag = new AccountDialog(0,acc);
    accDiag->exec();
}
void accountmanagerdialog::on_addButton_clicked()
{
    AccountDialog *accDiag = new AccountDialog(0);
    switch(accDiag->exec()) {
        case QDialog::Accepted:
        {
            ui->listWidget->addItem(makeListItem(accDiag->account));
            break;
        }
        case QDialog::Rejected:
            return;
    }
}
void MainWindow::add()
{
  AccountDialog *accountdialog = new AccountDialog(m, 1);
  accountdialog->exec();
}
void MainWindow::update()
{
  AccountDialog *accountdialog = new AccountDialog(m, 2);
  accountdialog->exec();
}
Beispiel #5
0
void
PreferencesAccounts::MessageReceived(BMessage* msg)
{
	switch (msg->what) {
		case kSelect: {
				int32 index;

				if (msg->FindInt32("index", &index) == B_OK) {
					fDelButton->SetEnabled(index >= 0);
					fEditButton->SetEnabled(index >= 0);
				}
			}
			break;
		case kAddAccount: {
			void *pointer = NULL;
			if (msg->FindPointer("settings", &pointer) == B_OK) {
				ProtocolSettings* settings
					= reinterpret_cast<ProtocolSettings*>(pointer);
				if (settings) {
					AccountDialog* dialog = new AccountDialog("Add account",
						settings);
					dialog->SetTarget(this);
					dialog->Show();
				}
			}
			break;
		}
		case kEditAccount: {
			for (int32 i = 0; i < fListView->CountItems(); i++) {
				int32 selected = fListView->CurrentSelection(i);
				if (selected < 0)
					continue;

				AccountListItem* item
					= dynamic_cast<AccountListItem*>(fListView->ItemAt(selected));

				AccountDialog* dialog = new AccountDialog("Edit account",
					item->Settings(), item->Account());
				dialog->SetTarget(this);
				dialog->Show();
			}
			break;
		}
		case kDelAccount: {
			for (int32 i = 0; i < fListView->CountItems(); i++) {
				int32 selected = fListView->CurrentSelection(i);
				if (selected < 0)
					continue;

				AccountListItem* item
					= dynamic_cast<AccountListItem*>(fListView->ItemAt(selected));

				const char* account = item->Account();
				ProtocolSettings* settings = item->Settings();
				if (settings->Delete(account) == B_OK)
					fListView->RemoveItem(item);
				delete settings;
			}
			break;
		}
		case kAccountAdded:
		case kAccountRenamed: {
			void* pointer = NULL;
			BString account;
			BString account2;

			if (msg->FindPointer("settings", &pointer) != B_OK)
				return;
			if (msg->what == kAccountAdded) {
				if (msg->FindString("account", &account) != B_OK)
					return;
			} else {
				if (msg->FindString("from", &account) != B_OK)
					return;
				if (msg->FindString("to", &account2) != B_OK)
					return;
			}

			ProtocolSettings* settings
				= reinterpret_cast<ProtocolSettings*>(pointer);
			if (!settings)
				return;

			if (msg->what == kAccountAdded) {
				// Add list item
				AccountListItem* listItem
					= new AccountListItem(settings, account.String());
				fListView->AddItem(listItem);

				// Add protocol/account instance
				TheApp* theApp = reinterpret_cast<TheApp*>(be_app);
				ProtocolManager::Get()->AddAccount(settings->AddOn(),
					account.String(), theApp->GetMainWindow());
			} else {
				// Rename list item
				for (int32 i = 0; i < fListView->CountItems(); i++) {
					AccountListItem* listItem
						= dynamic_cast<AccountListItem*>(fListView->ItemAt(i));
					if (!listItem)
						continue;

					if (account == listItem->Account()) {
						listItem->SetAccount(account2.String());
						break;
					}
				}
			}

			fListView->SortItems(compare_by_name);
			break;
		}
		default:
			BView::MessageReceived(msg);
	}
}