summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
AgeCommit message (Collapse)Author
2012-09-27Restructure the Uemis native download buffer codeGravatar Dirk Hohndel
Running under Valgrind showed a couple of silly bugs. Worse, intentionally running into various error scenarios showed that we could get the buffer handling in the raw parsing code to break down - we would fail to process the correctly downloaded files. To make it easier to get this right I restructured the code to collect the XML buffer in a different way - this works much better and has stood up well under testing so far. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-26Much improved handling of out of memory errors in the Uemis downloaderGravatar Dirk Hohndel
Instead of trying to figure out in the GUI code whether to call the downloader again, the logic was moved into the downloader itself. It now attempts to deal cleverly with running out of space on the dive computer filesystem - and in return is able to process the maximum number of dives (instead of just ten or so at a time). Even on partial reads before a failure we are able to collect the data that was completely transferred and report those dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-26Merge branch 'uemis-native'Gravatar Dirk Hohndel
This brings in the code to download dive information directly from a Uemis Zurich dive computer. The implementation contains a major hack that hooks the uemis code into the same data structures used to setup libdivecomputer. This gives the best result for the user, but is not something that I like as a long term solution as it relies on internal libdivecomputer data structures.
2012-09-26First implementation of native Uemis downloaderGravatar Dirk Hohndel
This includes one major hack that uses a private data structure from libdivecomputer to allow us to show the Uemis Zurich as one computer the user can import from. Once the user has chosen the Uemis we don't use libdivecomputer but our own downloader. Just like in the libdicecomputer case this runs in its own thread and updates the import dialog with progress information. The code also keeps track of the last dive that has been downloaded from a Uemis computer so we only import new dives on subsequent downloads. And since the Uemis Zurich gives us its device id, we make this a "per divecomputer" property for people who dive with multiple Uemis Zurich computers. This uses the debugfile infrastructure to allow easily collecting debugging output - especially on Windows where by default console output is lost. Known limitations: when the Uemis runs out of space (it uses its filesystem for communication with the host computer) we have no graceful way to reset things. This is why the code doesn't try to download ALL dives on the computer but instead download them in increments of ten dives. This clearly needs to be addressed once I understand how to reset the device. The Cancel button of the import dialog isn't correctly hooked up, yet. I still need to figure out how to gracefully shut down a download without potentially hanging the device. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-23Prevent a warning when showing the "About" dialogGravatar Lubomir I. Ivanov
gtk-gui.c:about_dialog(): Before assigning a pixel buffer to "logo" check if "image" has a GTK_IMAGE_PIXBUF storage type. Prevents the following message if the icon file is missing: Gtk-CRITICAL **: gtk_image_get_pixbuf: assertion The message that the file is missing is still shown. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-23Use the name "Subsurface" in the "About" dialogGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-23Make sure memory for default_dive_computer_device is allocatedGravatar Lubomir I. Ivanov
When calling gtk-gui.c:set_default_dive_computer_device(), first free memory at default_dive_computer_device and then use strdup(). This fixed a case, where after selecting a device for the first time in the "Download" dialog, then pressing "OK" followed by "Cancel" (after a device error) the device text is garbled the next time the dialog is opened. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-21Activate the new separate "Import XML File" functionalityGravatar Lubomir I. Ivanov
Renamed the function pick_import_files() to import_files() and added a declaration in "display-gtk.h". The declaration is "extern" for consistency with download_dialog(). Since the new dialog is a real child off "main_window", we no longer need some of the calls to gtk_widget_set_sensitive(), gtk_window_set_decorated() to disable the parent, which previously was the old "Import" combined dialog. Once the file list is retrieved, attempt to import each file and update the list via report_dives(). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Minor changes to file select box title Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-21Remove the XML file selection from the DC download dialogGravatar Lubomir I. Ivanov
Renamed "import_dialog" to "download_dialog" and also focused the download dialog strictly on dive computer functionality. Removed the file button and "filenames" checks from "download_dialog". Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-21Separate the "Import" menu entry into two menu entries in "File" and "Log"Gravatar Lubomir I. Ivanov
New entries with icons and shortcut keys in the menus. "Import XML File" is now using CTRL + I. Reserve CTRL + E for "Export XML File" if possible. "Download From Dive Computer" is using CTRL + D and a GTK_STOCK_GO_DOWN icon. Added separator below this entry in the "Log" menu. Note: menu entry callbacks are NULL at this stage. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-21Make sure windows behind forward dialogs are truly inactiveGravatar Lubomir I. Ivanov
There are possible bugs when targeting GTK 2.24.10. When opening the "import XML files" file selector from the "import" dialog on Ubuntu 12.04, even with gtk_window_set_accept_focus() setting FALSE to the parent ("import"), it is still possible to click the title bar and buttons, causing actions. This can trigger undefined behaviour - e.g. opening multiple "import XML files" dialogs. While on Windows the situation is more acceptable, on Ubuntu it is also possible to click the [x] button on the title bar of the parent window, which will close the parent dialog _with_ the current forward dialog. Multiple proposed methods in the GTK documentation seem not to function as expected, such as: gtk_window_set_modal() and gtk_window_set_accept_focus(). Passing the correct parent on dialog creation doesn't seems to help either. The same problem occurs when selecting a default file from the preferences dialog. The proposed portable solution in this patch is to completely disable the background windows by hiding the titlebar (gtk_window_set_decorated), disabling child controls (gtk_widget_set_sensitive) and making the window "transient for" or putting it on top (gtk_window_set_transient_for). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-21More cosmetic changes in the "Import" dialogGravatar Lubomir I. Ivanov
Renamed the XML button and titles slightly. Generalized the dialog topmost text to "Choose what to import:". Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-21Keep the "OK" button in "Import" disabled until a DC is selectedGravatar Lubomir I. Ivanov
Only call report_dives() for GTK_RESPONSE_ACCEPT in the same dialog. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2012-09-18Fix some of the problems reported by cppcheckGravatar Dirk Hohndel
Thanks to Christian for running the static code analysis tool against subsurface... There were some false positives, a few style issues that I'll ignore for now, and two actual potential bugs. First: Don't check unsigned variables for < 0 This has been around for a while and we are lucky that while technically a bug it still works as expected. Passing a negative idx simply turns it into a very large unsigned integer which then fails the > dive_table.nr test. So it still gets a NULL returned. A bug? Yes. Critical? No. Mismatched allocation and free This is an actual bug that potentially could cause issues. We allocate memory with malloc and free it with g_free. Not good. Reported-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Fixed a couple of memleaks in gtk-gui.c and info.cGravatar Lubomir I. Ivanov
Related to subsurface_default_filename() and g_path_get_basename(). Against 3835faa8fb02df8edb. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Added an entry "New" in the "File" menuGravatar Lubomir I. Ivanov
Currently doubles the functionality of "Close" (file_close). Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Fix crash when simply clicking OK in import dialogGravatar Dirk Hohndel
Since the GSList is now only created if the user enters the file selection dialog, opening the import dialog and then clicking OK without selecting either a dive computer or a file would cause a crash. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Generalized the "Import" dialog titleGravatar Lubomir I. Ivanov
Renamed the title of the "Import" dialog to "Import", as there are a couple of supported operations. Removed the "Import:" text in the dialog body. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-18Moved "Import" in a separate section in the "File" menuGravatar Lubomir I. Ivanov
Moved the entry bellow the standard file operations and above "Print". Also placed it between separators and added the GTK_STOCK_GO_BACK icon. Later on "Export" can be placed below "Import" using GTK_STOCK_GO_FORWARD. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Merge branch 'defaultfile'Gravatar Dirk Hohndel
By now the default file code seems quite matured, so in preparation for 2.0 we'll bring it back into master. I made a few small clean-ups during the merge, but the merge itself is very much straight forward. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Simplify code in file_open as we now only open one fileGravatar Dirk Hohndel
This doesn't change functionality - it's just pointless to loop over a list that is known to have only one element. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Don't close existing data file in file_open if user cancelsGravatar Dirk Hohndel
This logic seems to make much more sense - if the user hits 'OK' then the old file is closed and the new one openened. Otherwise, leave things unchanged. Reported-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Once again improve existing filename handlingGravatar Dirk Hohndel
Several potential problems. - we could end up dereferencing exiting_filename when it was NULL - we could free the default_filename by mistake - subsurface_default_filename always needs to return a copy of it - closing the existing file before opening a new one repopulated the existing_filename with the default filename - preventing the opened file to become the new existing filename Also, make existing filename a const char * and make file_open have the same sensible default folder behavior as the other file related functions. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Mark divelist unchanged after closing the datafileGravatar Dirk Hohndel
This seems rather obvious - I'm surprised I didn't notice it earlier. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Put creation of the file selector box filter into helper functionGravatar Dirk Hohndel
This avoids duplication of code. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Reimplement the GtkFileChooserButton for importGravatar Dirk Hohndel
One of the limitations of GtkFileChooserButton is that it only allows one file to be chosen (so that it can display that file name in the button after the file chooser dialog finishes). Since in the import dialog we never want to show the button with the filename(s) filled in but want to directly execute the import once files have been selected, I reimplemented the button to simply open a multi file chooser when clicked and to then run the import function if one or more file names were selected. This does appear to require some more code but gets us a much more useful and consistent implementation. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17The Open menu entry should open just one fileGravatar Dirk Hohndel
The single file that is our new data file (and the file that we'll change if it was modified). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Move Import menu entry back to File menuGravatar Dirk Hohndel
This should make things more consistent, especially now that "Open" actually does just that and no longer behaves almost like "Import". The downside is that the import from a dive computer is now in the File menu as well and no longer in the Log menu, where Linus originally had moved it to in commit 3cace090989b. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17File Open now closes the previous file, firstGravatar Dirk Hohndel
This is a pretty significant semantic change - Open used to act more like Import; you added more dives to the divelist. With this change it instead acts more like the traditional File->Open in that it closes the previous file, first. The diff hides the minimalistic nature of the change - it seemed cleaner to move the file_open function around than to do a forward declaration of file_close. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-17Display current filename in windows titleGravatar Dirk Hohndel
This seems to make sense since we have a pretty strong concept of the "active file" that we are working on. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13Use glib file and pathname functionsGravatar Dirk Hohndel
My silly reimplementation of these functions was broken on Windows, anyway. This is much cleaner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13Prevent the preferences dialog from getting focus with file selector openGravatar Dirk Hohndel
The idea is based on Lubomir's code but the implementation is radically different. Instead of having the preferences dialog be referenced by a global variable we simply look up the appropriate ancestor of the current widget. Inspired-by: "Lubomir I. Ivanov" <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-13Fix memory leaks and one potential NULL dereferenceGravatar Dirk Hohndel
Always make sure to clear the memory allocated at the "existing_filename" pointer when setting it to a new address or NULL. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Lifted these changes from a larger commit. The other changes I'll reimplement in the next commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-12various small fixes to the defaultfile modelGravatar Lubomir I. Ivanov
1) For safety reasons we no longer remove the default directory after creating it. This prevents an access error (on windows) and also a couple of small exploits that could have been possible, resulting in undefined behaviour. 2) Once "default_filename" is allocated keep it until the value has to change. The value is finaly released once the program is ready to close. 3) When picking a new default file, grab the new string directly from the GSList. 4) When storing the new default file from the preferences dialog, make sure we also update "existing_filename" if needed. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Fixed some whitespace issues, made commit message and one of the comments in the code somewhat clearer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-12Make sure Subsurface receives Quit / Command-Q callback on MacGravatar Dirk Hohndel
As usual, things work slightly different on Mac. Quartz delivers some (but not all) accelerator notifications differently. Command-Q and Subsurface->Quit now work on Mac as well. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11Inline g_list_free_full for better compatibilityGravatar Lubomir I. Ivanov
Replaced g_list_free_full with the inlined alternave: g_list_foreach(dive_trip_list, (GFunc)free, NULL); g_list_free(dive_trip_list); once again my version on debian 6.0.x has libraries up-to-date yet outdated. i guess i have to suggest against API which has the "Since <some ver>" text and <some ver> is fairly recent on documentation webpages. Signed-off-by: "Lubomir I. Ivanov" <neolit123@gmail.com> I took only one hunk from the patch that Lubomir sent - the rest I implemented differently in the previous commit. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11Use glibio functions for mkdirGravatar Dirk Hohndel
Suggested-by: Jef Driesen <jefdriesen@telenet.be> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11Better compatibility with older GTK and CairoGravatar Lubomir I. Ivanov
divelist.c: Replaced "gtk_tree_path_get_indices_with_depth()" with the coupled alternative: int depth = gtk_tree_path_get_depth(path); int *indices = gtk_tree_path_get_indices(path); for compatibility GTK+ < 2.22 *: Replaced all usage of "cairo_rectangle_int_t" with "cairo_rectangle_t" for compatibility with Cairo < 1.10. Both modification make building Subsurface possible on a fairly recent Debian distribution, which reports to have the version of the abovementioned libraries "up-to-date", yet they are slightly outdated. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11Display yearly/monthly statisticsGravatar Miika Turkia
Display yearly statistics in a statistics window with option to expand the viewing on monthly level. The amount of dives along with basic information like duration, depth, water temperature and air consumption is displayed in yearly and monthly level. Thus you are able to compare e.g. development of air consumption or diving activity from year to year. Using already existing macro for splitting seconds into minutes:seconds. Moving repetitive code to a function (couldn't think of the suggested clever macro, but this should pretty much do the trick). Now the statistics are updated every time the process_all_dives function is called. It might make sense to actually verify the structures need to be re-allocated, but such optimization is currently not implemented. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Combined two commits. Minor cleanups for white space and boolean values. Significant changes to use the correct units for volumes vs. depths and to avoid unneccesary lookups of the model storage based on the tree. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-11Use GTK_UNIT_INCH when printing to provide consistency across OSGravatar Lubomir I. Ivanov
Tests have shown that the most multi-platform way to do printing with GTK is to use GTK_UNIT_INCH (or GTK_UNIT_MM) with GtkPrintOperation. Tested on Linux, OSX, Windows. However this requires the appropriate scaling for Pango and Cairo to be done, with separate plotting logic for printing and drawing on the screen. To achieve that, profile.c:plot() now accepts a scaling parameter from type "scale_mode_t" defined in "display.h". Also due to new scale, small decimal numbers (such as 6.12345) cannot be well stored in "cairo_rectangle_int_t" therefore it is replaced with "cairo_rectangle_t", which uses doubles to provide Cairo with a drawing area. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Minor whitespace cleanup. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10Fix silly folder permission bugGravatar Dirk Hohndel
I forgot to give the user execute permission on the folder that subsurface might create to store the datafile in. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10Implement Close menu option that allows closing the data fileGravatar Dirk Hohndel
This requires some helper routines that allow us to clear out all the widgets. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-10Change behavior for the existing filenameGravatar Dirk Hohndel
Previously we always picked the last file that was openend as the file name to save to. That seems counterintuitive when importing files or when opening multiple files. Especially if Subsurface was executed without a file on the command line and we are using the default file. Now we only remember a file name if it was the first one to ever be openend or if it was used in save-as. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-09First cut of adding a default file nameGravatar Dirk Hohndel
The default file name is OS specific and tries to follow the customs on each of the OSs. It can be configured through the preferences dialog. On MacOS we get a strange warning which appears to be a well documented Gtk bug on MacOS. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-06Set default path for file import to the last path openedGravatar Dirk Hohndel
This may not be the path the import files are in, but it's better than the current default of 'nothing'. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-06Update the About screenGravatar Dirk Hohndel
Add the current year and the second main author, err, me. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-03Correctly initialize the toggle state of the autogroup menu entryGravatar Dirk Hohndel
If we move to Linus' tri-state variable we need to separate those two items, anyway. But for now this fixes the obvious bug. Reported-by: Henrik Brautaset Aronsen <subsurface@henrik.synth.no> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-09-02Add autogen menu commandGravatar Dirk Hohndel
This adds the ability to auto create trips from the menu. It's a toggle entry (and while at it, we made the zoom toggle a toggle entry as well). We can therfore switch back and forth between auto generated trips. There is one bug. Assume you have no trips. You manually create a trip from some dives out of a group of trips that autogen would turn into a trip. Now you turn on autogen and this trip gets expanded with all the dives that would normally be grouped together. If you turn off autogen again, all those dives are still part of the remaining (initially manually created) trip. Working around this issue seemed a lot more work than the likelihood of anyone running into it seemed worth. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2012-08-28Merge branch 'freediving-tweaks' of git://github.com/mguentner/subsurfaceGravatar Linus Torvalds
Merge freediving tweaks (zoom in on short dives etc) from Maximilian Güntner. Trivial conflicts in display.h due to unrelated printing stuff just happening to be added nearby. * 'freediving-tweaks' of git://github.com/mguentner/subsurface: moved zoomed_plot to display.h plot the time with a fixed padding (leading zero) updated/corrected comment added "Zoom" button and improved scaling fixed indentation use increments that make sense for 600 seconds Plot shorter (apnea) dives with a reasonable scale
2012-08-28Merge git://git.tdb.fi/ext/subsurfaceGravatar Linus Torvalds
Pull a few buglet fixes from Mikko Rasa. Some trivial conflicts due to changes in the dive selection logic, and using the new "for_each_dive()" helper. * git://git.tdb.fi/ext/subsurface: Check if multi-dive editing is actually needed Fix an off-by-one error in buffer allocation