#include "addresstablemodel.h"
#include "editaddressdialog.h"
#include "csvmodelwriter.h"
+#include "guiutil.h"
#include <QSortFilterProxyModel>
#include <QClipboard>
-#include <QFileDialog>
#include <QMessageBox>
AddressBookPage::AddressBookPage(Mode mode, Tabs tab, QWidget *parent) :
void AddressBookPage::setModel(AddressTableModel *model)
{
this->model = model;
+ if(!model)
+ return;
// Refresh list from core
model->updateList();
connect(ui->tableView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
this, SLOT(selectionChanged()));
- if(mode == ForSending)
- {
- // Auto-select first row when in sending mode
- ui->tableView->selectRow(0);
- }
selectionChanged();
}
-QTableView *AddressBookPage::getCurrentTable()
-{
- return ui->tableView;
-}
-
void AddressBookPage::on_copyToClipboard_clicked()
{
// Copy currently selected address to clipboard
// (or nothing, if nothing selected)
- QTableView *table = getCurrentTable();
+ QTableView *table = ui->tableView;
+ if(!table->selectionModel())
+ return;
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
foreach (QModelIndex index, indexes)
void AddressBookPage::on_newAddressButton_clicked()
{
+ if(!model)
+ return;
EditAddressDialog dlg(
tab == SendingTab ?
EditAddressDialog::NewSendingAddress :
void AddressBookPage::on_deleteButton_clicked()
{
- QTableView *table = getCurrentTable();
+ QTableView *table = ui->tableView;
+ if(!table->selectionModel())
+ return;
QModelIndexList indexes = table->selectionModel()->selectedRows();
if(!indexes.isEmpty())
{
void AddressBookPage::selectionChanged()
{
// Set button states based on selected tab and selection
- QTableView *table = getCurrentTable();
+ QTableView *table = ui->tableView;
+ if(!table->selectionModel())
+ return;
if(table->selectionModel()->hasSelection())
{
void AddressBookPage::done(int retval)
{
+ QTableView *table = ui->tableView;
+ if(!table->selectionModel() || !table->model())
+ return;
// When this is a tab/widget and not a model dialog, ignore "done"
if(mode == ForEditing)
return;
// Figure out which address was selected, and return it
- QTableView *table = getCurrentTable();
QModelIndexList indexes = table->selectionModel()->selectedRows(AddressTableModel::Address);
foreach (QModelIndex index, indexes)
void AddressBookPage::exportClicked()
{
// CSV is currently the only supported format
- QString filename = QFileDialog::getSaveFileName(
+ QString filename = GUIUtil::getSaveFileName(
this,
- tr("Export Address Book Data"),
- QDir::currentPath(),
+ tr("Export Address Book Data"), QString(),
tr("Comma separated file (*.csv)"));
if (filename.isNull()) return;