Commit graph

39 commits

Author SHA1 Message Date
Lubomir I. Ivanov
ab95da8fd2 Update main window title depending of current file state
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@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-27 07:23:12 +08:00
Dirk Hohndel
370673cc99 Improve display of yearly statistics
Display the units in the header, make the header more consistent
looking, convert the values into the right units with appropriate
precision.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 10:48:46 -07:00
Dirk Hohndel
29b242c703 Converting the device_info list into a Qt data structure
This data structure was quite fragile and made 'undo' when editing
rather hard to implement. So instead I decided to turn this into a
QMultiMap which seemed like the ideal data structure for it.

This map holds all the dive computer related data indexed by the model. As
QMultiMap it allows multiple entries per key (model string) and
disambiguates between them with the deviceId.

This commit turned out much larger than I wanted. But I didn't manage to
find a clean way to break it up and make the pieces make sense.

So this brings back the Ok / Cancel button for the dive computer edit
dialog. And it makes those two buttons actually do the right thing (which
is what started this whole process). For this to work we simply copy the
map to a working copy and do all edits on that one - and then copy that
over the 'real' map when we accept the changes.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-18 00:24:28 -07:00
Dirk Hohndel
cb50d6bf6c Process dive computers as they are read in
When doing the early port from the Gtk code to Qt this function was just
stubbed out. Now we are correctly filling the internal data structures
with ALL the dive computers that we see.

Instead of the silly dialog asking the user for a nickname we simply
create one from the deviceid. The user can then use the device name
editing dialog to create more intuitive nicknames.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-06-17 11:48:58 -07:00
Tomaz Canabrava
478c24d797 Removed the buttons on the Edit Dive computers.
This edit dive computers thing doesn't really need buttons anyway.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-06-07 14:59:06 -03:00
Dirk Hohndel
5c2a2691fd Much better solution to avoid the gtk+ style on Linux
Thiago showed me how to find out which style is in use and if we see a
user is running gtk+ we simply switch Subsurface to Oxygen (using the
old plastique in the previous patch was a result of reading an old Qt
book, I guess).

Solved-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-31 17:43:38 +10:00
Dirk Hohndel
34c7aa940c Hack to force plastique style on Linux
I'd much rather be able to check if it is using the Gnome style and only
then force plastique but I haven't been able to figure out how to do
that.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-31 12:40:52 +09:00
Dirk Hohndel
c972c7cbd9 Display the Subsurface manual in the help widget
This adds a helper function to determine the Subsurface data directory
(are we running from build directory? installed on Linux? installed on
Mac? - still need to add support for Windows). This same function is
then used by both the setup for Marble and for the help browser.

This assumes that the user-manual.html file has actually been built and
installed (which we don't do by default with the current Makefile).

Right now there are rendering issues with our manual in the help browser
widget - I'm sure this can be fixed...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-31 06:26:56 +09:00
Dirk Hohndel
4f53ad736d Connect preferences to the rest of the code
The biggest problem here was that bool has different sizes in C and C++
code. So using this in a structure shared between the two sides wasn't a
smart idea.

Instead I went with 'short', but that caused problems with Qt being to
smart for its own good and not doing the right thing when dealing with
'boolean' settings and a short value. This may be something in the way I
implemented things (as I doubt that something this fundamental would be
broken) but the workaround implemented here (explicitly using 0 or 1
depending on the value of the boolean) seems to work.

I also decided to get rid of the confusion of where gflow/gfhigh are
floating point (0..1) and when they are integers (0..100). We now use
integers anywhere outside of deco.c.

I also applied some serious spelling corrections to the preferences
dialog's ui file.

Finally, this enables the code that selects which partial pressure graph
to show.

Still to do: font size, metric/imperial logic

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-29 12:59:46 +09:00
Alberto Mardegan
5e0a3cdad8 Fix usage of temporary QByteArrays
This commit fixes three different things:
 - a memory leak in WeightModel::setData()
 - getSetting() calling strdup() on a QByteArray
 - a possible usage of memory after deallocation

Here's an explanation of the last issue (taken from the mailing list, slightly
adapted):

toByteArray(), as well as others "toSomething()" methods, returns
a new object which the compiler allocates on the stack.  The compiler
will consider it a temporary data, and destroy it on the next line.  So,
when one does

	char *text= value.toByteArray().data(); // line 1
	if (strcmp(description, text)) {        // line 2

the compiler creates a QByteArray on line 1, calls ::data() on it, which
returns a valid char *, and assigns its value to "text".  So far, so
good.  But before jumping to line 2, the compiler destroys the temporary
QByteArray, and this will in turn invoke the QByteArray destructor,
which will destroy the internal data. The result is that on line 2,
"text" will point to some memory which has already been freed.

One solution is to store a copy of the temporary QByteArray into a local
variable: the compiler will still destroy the temporary QByteArray it created,
but (thanks to the reference-counted data sharing built in QByteArray) now the
destructor will see that the data is referenced by another instance of
QByteArray (the local variable "ba") and will not free the internal data.
In this way, the internal data will be available until the local variable is
destroyed, which will happen at the end of the {} block where it is defined.

Please note that when one uses the data in the same line, one doesn't need to
worry about this issue. In fact,

  text = strdup(value.toString().toUtf8().data());

works just fine.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-24 06:18:27 -07:00
Dirk Hohndel
641db88a2c Remove a compile warning
It's cleaner to make this a QString, anyeway.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-23 18:36:18 -07:00
Dirk Hohndel
c917a99eb2 Implement default dive computer and device
The data is saved in the settings and the correct dive computer (vendor
and product) and device are picked when the download dialog is openend.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-22 23:24:33 -07:00
Dirk Hohndel
478baf1076 Replace GError handling with a kMessageWidget based approach
Instead of passing pointers to GError around we pass just pointers to
error message texts around and use kMessageWidget to show those. Problem
is that right now the close button on that doesn't do a thing - so the
error stays around indefinitely. Oops.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21 23:39:49 -07:00
Dirk Hohndel
5aa8b52f82 Remove Gtk crud
The DEBUGFILE logic isn't needed anymore. Nor are helpers dealing with
model / datastructure updates. Nor conditional compiles to use Gtk instead
of Qt.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21 20:48:11 -07:00
Dirk Hohndel
6d3a4ec9b2 Initialize QSettings earlier & change the Organization to "Subsurface"
The first change allows the default_filename to be found again.
The second change switches us to .config/Subsurface/Subsurface.conf which
I find much more useful.

QtCreator also fixed a few indentation issues for me. How helpful.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-21 20:37:32 -07:00
Tomaz Canabrava
f7c78a20bd Removing an kinky settings that I forgot to.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-21 23:09:44 -03:00
Tomaz Canabrava
3fdea49e70 Fixed the hide / show columns using the settings.
This also changed a bit the behavior on how the QSettings are managed,
till now, we used the QSettings constructor passing the name of the
software and the 'company', but this is now default - so there's no
need to pass anything by the QSettings contructor.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-21 23:07:19 -03:00
Tomaz Canabrava
f4acbb02e4 Populate the Vendor && Dive computer information.
This uses the QStringListModel to populate the items
of the QComboBoxes. I used a QHash to hold every Computer
of a particular Vendor. so, products[vendor] gives me
the full list of products from each vendor.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-05-20 17:58:06 -03:00
Amit Chaudhuri
97a044d41f Tweaks to maintab
Align statistics tab labels as per infotab.

Amend helper function to show degree symbol for temp measurements.

Change order of member initialisation list to match order of decl
(ProfileGraphicsView::ProfileGraphicsView)

Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-10 16:01:17 -07:00
Dirk Hohndel
fe6237b273 Implement the get_screen_dpi function
This is sadly known to be incorrect on most systems. But it's as incorrect
as it was on Gtk so should work equally well to get roughly the right
sizes for printing - once we implement printing, that is :-)

Also removed a qDebug that snuck in in commit 6fc4d72079dd ("Enable
defautl_filename in settings").

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-10 10:47:37 -07:00
Dirk Hohndel
ed6a54f506 Enable defautl_filename in settings
We don't have a UI to set it, yet, so you have to manually set it in the
config file, but once you do that it works...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-09 21:37:21 -07:00
Dirk Hohndel
b75a89aa86 Start populating the maintab Dive Info widget
Establish some useful helpers and use them when updating the values.

One of the helpers (from statistics.c) puzzlingly doesn't link - so that's
ifdefed out.

Also had to re-arrange the settings reading code (it came too late) and to
extract the expanding code of the top dive from the settings reading code
(as it had no business being there to begin with).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-06 20:38:38 -07:00
Dirk Hohndel
e960a5b558 Add most settings to the QSettings code
This is missing the char * based settings (as I have no idea how to do
those) plus the map provider. Everything else should work.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-05 21:11:08 -07:00
Dirk Hohndel
8677721e85 Remove the majority of the Gtk related code
- rip all Gtk code from qt-gui.cpp
- don't compile Gtk specific files
- don't link against Gtk libraries
- don't compile modules we don't use at all (yet)
- use #if USE_GTK_UI on the remaining files to disable Gtk related parts
- disable the non-functional Cochran support while I'm at it

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-05-03 11:37:09 -07:00
Dirk Hohndel
1d0d42f861 Remove the explicit UTF-8 conversions
Thanks to commit bdbfdcdfa0fb ('Ask Qt 4 to use the UTF-8 codec as the
"codec for C strings"') we no longer need the explicit UTF-8 conversion
when creating QStrings from char *.

Suggested-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-25 21:10:05 -07:00
Thiago Macieira
8da7a6985b Ask Qt 4 to use the UTF-8 codec as the "codec for C strings"
Qt 5 does this by default, so it's not necessary there (in fact,
setCodecForCStrings was removed, so you catch any mistakes).

Now all QString methods taking a const char* or QByteArray
(constructor, append(), operator+=, operator<, etc.) will interpret
that char array as UTF-8. Conversely, the QByteArray methods taking a
QString will generate UTF-8 too. This includes the badly named
QString::fromAscii() and QString::toAscii().

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-25 20:11:36 -07:00
Thiago Macieira
72ad76fc26 Fix compilation: in C++, enums don't have operator++
To use ++, we need to declare the variable as int. But then we need to
cast to the enum type.

This is using C-style casts because this is still C-like code.

Signed-off-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-23 08:06:00 -07:00
Dirk Hohndel
5da11cbc6a Fix crash with some setups
Initialize Qt earlier, before Gtk gets its hands on argc / argv.

Suggested-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-22 06:45:57 -07:00
Amit Chaudhuri
073be111f4 Delay Qt ui construction
The Qt ui will need to read the dive_table to populate widgets with
dives. Gtk functionality in init_ui is required to parse the dives.
Split init_ui to allow parsing to proceed and complete before Qt ui
mainwindow constructor is called.

Play with qDebug()'s printf style (Thiago!)

Signed-off-by: Amit Chaudhuri <amit.k.chaudhuri@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-18 12:31:15 -07:00
Dirk Hohndel
d8e11439ad Undoing the last Qtr_ hack
The Qtr_ hack isn't needed as in commit 720fc15b2dcd ("Introduce
QApplication") had already made sure that we are using gettext.

I didn't revert the two commits as I wanted to keep the added header
comments and fix the tooling in the Makefile as well.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-14 06:58:56 -07:00
Dirk Hohndel
f5c958ad73 Add Qtr_ macros that uses gettext in a tr() compatible manner
This should wrap gettext nicely and replace the "_()" macros we use in C
code.

Also added comments to the top of all the new files.

Suggested-by: Thiago Macieira <thiago@macieira.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-13 20:44:02 -07:00
Tomaz Canabrava
92397a2bad Started the real code on the Qt Interface.
1 - Open File already open files, it tries to not break the Gtk version,
    but some methods on the GTK version still need to be called inside Qt
    because the code is too tight-coupled.

2 - Close file already close files, same comments for the open file dialog
    applies here.

3 - The code for adding new cylinders in the cylinder dialog is done,
    already works and it's integrated with the system.  There's a need to
    implement the edit and delete now, but it will be easyer since I'm
    starting to not get lost on the code.

4 - Some functions that were used to convert unities have been moved to
    convert.h ( can be changed later, put there because it's easyer to
    find something that converts in a convert.h =p ) because they were
    static functions that operated in the GTK version but I need those
    functions in the Qt version too.

[Dirk Hohndel: lots and lots of whitespace and coding style changes]

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-13 14:08:16 -07:00
Dirk Hohndel
4cf244e228 Fix some of the gcc-4.8 warnings
Most of the warnings are IMHO false positives:
e.g.: an enum variable is initialized in a switch statement that has a case for
      each possible enum value - yet gcc 4.8 warns that it could be used
      uninitialized;
or:   two variables are initialized together in the code - second one of them
      is previously initialized to -1 at declaration time, both are initialized
      in an if (second one == -1) clause - so they are guaranteed to both be
      initialized...
I did not "fix" those as the code is actually correct.

But there are three spots where it catches things that could indeed go wrong
(with odd input data in one of them).

This commit also adds a check to only call g_type_init() for older versions of
glib as in newer ones it is deprecated.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07 20:25:14 -07:00
Tomaz Canabrava
ba712c3b54 Start creating the Qt UI
This is based on several commits from Tomaz - mingled together and mildly
extended by Dirk (mostly Makefile hacking).

All Qt UI related stuff should eventually move into the qt-ui directory.
So the Makefile rules for moc and uic have been adjusted accordingly.

The MainWindow class has been moved into its own file in qt-ui (but just
with a placeholder, the existing class has simply been ifdef'ed out in
qt-gui.cpp for the moment).

We still have a couple of Qt things in qt-gui.cpp in the main directory...
all this needs to move into the qt-ui directory and be built with separate
.h files. Right now we have the one-off Makefile rule to create the
qt-gui.moc file from the qt-gui.cpp file.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-04-07 15:59:33 -07:00
Alberto Mardegan
a412753b0a Add a Qt main window
This is just an empty window with a File menu and a few items.
It shows how to hook up functions to menu actions.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
2013-04-02 19:55:53 +03:00
Alberto Mardegan
2f759f52e1 Move set_filename() calls outside of parse_file()
Remove the boolean parameter from parse_file; the code is more readable
by having an explicit call to set_filename() where necessary, rather
than a boolean parameter.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
2013-04-02 19:55:44 +03:00
Alberto Mardegan
40e3671bd2 Improve Makefile rules for running moc
The previous rules were conflicting, and the naming of the moc-generated
file to be included in .cpp files was deviating from what's most used in
Qt: the usual way is to
  #include "file.moc"
and not
  #include "file.moc.cpp"

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
2013-04-01 23:11:25 +03:00
Alberto Mardegan
7ea2281180 Introduce QApplication
Instantiate a QApplication and let Qt handle the event loop.
Add a QTranslator subclass to translate the UI via gettext.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
2013-04-01 16:03:59 +03:00
Alberto Mardegan
578d633d01 Have some C++ file in the project
Rename gtk-gui.c to qt-gui.cpp, and make the necessary changes so that
the project still builds.

Signed-off-by: Alberto Mardegan <mardy@users.sourceforge.net>
2013-04-01 16:03:59 +03:00
Renamed from gtk-gui.c (Browse further)