[PATCH 5/5] Update main window title depending of current file state

Dirk Hohndel dirk at hohndel.org
Wed Jun 26 09:41:33 PDT 2013


I got this one twice but no 1/5...

it's past midnight here so I'll take a look at this (and other patches
that have come in the last 36h, including the Italian translation)
tomorrow.

I'm hoping to do the 3.1.1 release on Saturday (in case anyone has any
final changes they want to get into that). Hopefully that will be our
last 3.x release so we can focus on getting a 4.0 beta out...

/D

On Wed, 2013-06-26 at 15:13 +0300, Lubomir I. Ivanov wrote:
> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
> 
> If a file has been opened from the command line or via the File
> menu the main window title becomes "Subsurface: filename.ext".
> Title also updates if 'File->Save As' is called. "Subsurface" only
> is displayed when no active file is present or post 'File->New'
> or 'File->Close'.
> 
> To make this work a new public method is added - MainWindow::setTitle()
> and also an enum type MainWindowTitleFormat, which should allow
> more complicated formatting, such as showing the selected dives
> or the total number of dives (e.g. MWTF_FILENAME_N_DIVES).
> 
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
> fixed a small coding style error compared to the previous patch 5 version.
> ---
>  qt-gui.cpp           |  4 ++++
>  qt-ui/mainwindow.cpp | 18 ++++++++++++++++++
>  qt-ui/mainwindow.h   |  3 +++
>  3 files changed, 25 insertions(+)
> 
> diff --git a/qt-gui.cpp b/qt-gui.cpp
> index 2474d40..eab282d 100644
> --- a/qt-gui.cpp
> +++ b/qt-gui.cpp
> @@ -75,6 +75,10 @@ void init_qt_ui(int *argcp, char ***argvp, char *errormessage)
>  	MainWindow *window = new MainWindow();
>  	window->showError(errormessage);
>  	window->show();
> +	if (existing_filename && existing_filename[0] != '\0')
> +		window->setTitle(MWTF_FILENAME);
> +	else
> +		window->setTitle(MWTF_DEFAULT);
>  }
>  
>  const char *getSetting(QSettings &s, QString name)
> diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
> index 6036b3c..0655e7a 100644
> --- a/qt-ui/mainwindow.cpp
> +++ b/qt-ui/mainwindow.cpp
> @@ -120,6 +120,7 @@ void MainWindow::on_actionOpen_triggered()
>  	char *error = NULL;
>  	parse_file(fileNamePtr.data(), &error);
>  	set_filename(fileNamePtr.data(), TRUE);
> +	setTitle(MWTF_FILENAME);
>  
>  	if (error != NULL) {
>  		showError(error);
> @@ -164,6 +165,7 @@ void MainWindow::on_actionClose_triggered()
>  	ui->ProfileWidget->clear();
>  	ui->ListWidget->reload(DiveTripModel::TREE);
>  	ui->globe->reload();
> +	setTitle(MWTF_DEFAULT);
>  
>  	clear_events();
>  }
> @@ -673,6 +675,7 @@ void MainWindow::file_save_as(void)
>  	if (!filename.isNull() && !filename.isEmpty()) {
>  		save_dives(filename.toUtf8().data());
>  		set_filename(filename.toUtf8().data(), TRUE);
> +		setTitle(MWTF_FILENAME);
>  		mark_divelist_changed(FALSE);
>  	}
>  }
> @@ -705,3 +708,18 @@ void MainWindow::showError(QString message)
>  	ui->mainErrorMessage->setMessageType(KMessageWidget::Error);
>  	ui->mainErrorMessage->animatedShow();
>  }
> +
> +void MainWindow::setTitle(enum MainWindowTitleFormat format)
> +{
> +	switch (format) {
> +	case MWTF_DEFAULT:
> +		setWindowTitle("Subsurface");
> +		break;
> +	case MWTF_FILENAME:
> +		QFile f(existing_filename);
> +		QFileInfo fileInfo(f);
> +		QString fileName(fileInfo.fileName());
> +		setWindowTitle("Subsurface: " + fileName);
> +		break;
> +	}
> +}
> diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
> index 8582595..bac7468 100644
> --- a/qt-ui/mainwindow.h
> +++ b/qt-ui/mainwindow.h
> @@ -31,6 +31,8 @@ class MainTab;
>  class ProfileGraphicsView;
>  class QTextBrowser;
>  
> +enum MainWindowTitleFormat { MWTF_DEFAULT, MWTF_FILENAME };
> +
>  class MainWindow : public QMainWindow
>  {
>  Q_OBJECT
> @@ -43,6 +45,7 @@ public:
>  	DiveListView *dive_list();
>  	GlobeGPS *globe();
>  	void showError(QString message);
> +	void setTitle(enum MainWindowTitleFormat format);
>  
>  private slots:
>  




More information about the subsurface mailing list