1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-16 21:05:00 +02:00
Commit Graph

822 Commits

Author SHA1 Message Date
Maarten ter Huurne
0b0e278459 Deal gracefully with the selector being started on a non-existent dir
If directory browsing is enabled, fall back to the closest existing
parent directory. If directory browsing is disabled, show empty list.
2014-08-17 10:05:21 +02:00
Maarten ter Huurne
9e22b0328f Made new "no items" text in Selector translatable 2014-08-17 08:41:09 +02:00
Maarten ter Huurne
e2382e11fd Made SettingsDialog::exec() return whether a setting was changed
Previously, exec() always returned true and a separate edited() method
would indicate whether any settings were changed.
2014-08-16 17:11:18 +02:00
Maarten ter Huurne
faf2495727 Use unique_ptr to make ownership of MenuSettings explicit 2014-08-16 17:01:04 +02:00
Maarten ter Huurne
8a1bb5694f Renamed SettingsDialog::voices to settings
I have no idea where that original name came from, but it didn't make
any sense to me.
2014-08-16 16:43:26 +02:00
Maarten ter Huurne
dc39fcc01f Make Selector robust against an empty file list
This can happen on a directory with 0 file matches when directories are
not being shown (otherwise there is either ".." or a subdir).

Since there is nothing to be selected, the Accept button is disabled
and no cursor is shown.
2014-08-16 15:50:16 +02:00
Maarten ter Huurne
3cce71284a Redistribute any leftover vertical space in Selector 2014-08-16 15:42:33 +02:00
Maarten ter Huurne
ffb736d80f Log surface load failures at DEBUG level instead of ERROR
Since we no longer check file existance before attempting a load,
load failures are often not errors. For example a missing preview
image is harmless.
2014-08-16 15:42:33 +02:00
Maarten ter Huurne
d16cb902b3 Improved Selector's handling of the folder icon
Renamed fontHeight to lineHeight, since it is computed using both the
font's line spacing and the height of the folder icon. For the latter,
use the actual icon height plus two pixels spacing instead of the
hardcoded value of 20 (16 height + 4 pixels spacing).

Fixed recently introduced bug where "top" is added to the folder icon
y-coordinate twice. Also center the icon vertically when a large font
is used.

Don't crash if the folder icon is missing. This could only happen on
broken installations though. Also don't search for the icon twice:
SurfaceCollection::skinRes already calls addSkinRes internally when
there is no cached surface for the key.
2014-08-16 15:41:06 +02:00
Maarten ter Huurne
88a4d1d911 Minor cleanups in Selector
Removed unused data member selRow.
Keep reference to LinkApp instead of pointer.
Call LinkApp::getSelectorBrowser once and store result.
Renamed fontheight to fontHeight.
Use iY consistently: store the item's y-coordinate in it.
2014-08-16 07:31:33 +02:00
Nebuleon Fumika
9b583f9b38 Rearrange calls to GMenu2X::drawButton from left to right
This breaks up large reversed call chains in a few places.
2014-08-16 07:11:30 +02:00
Maarten ter Huurne
fe0db484ec Removed "delegate.h"
The abstraction it provided was so thin that I think it is simpler to
just have the code use std::bind directly.
2014-08-16 07:07:41 +02:00
Maarten ter Huurne
7e308879c1 Pass action to IconButton constructor
This removes the need for a separate setAction method.

The default action is the empty action, which does nothing. However,
a touch event on a button with the empty action is no longer considered
handled.

Menu::btnContextMenu was changed from a unique_ptr to a plain data
member.
2014-08-16 06:44:13 +02:00
Maarten ter Huurne
428a316bc1 Removed GMenu2X pointer from ButtonBox
It was only used to fetch resY, so I replaced that by taking the
y-coordinate as an argument. That is also more consistent with the
x-coordinate which was already an argument.

The x-coordinate was changed to a signed int, since that is the norm
for paint coordinates. It can be useful for drawing widgets that are
partially off screen, for example during a (dis)appear animation.

In InputDialog, the ButtonBox field was changed from a pointer to
a plain data member. There was no need to dynamically allocate it.
2014-08-16 05:52:25 +02:00
Maarten ter Huurne
e5a432cb6b In C++11, it is no longer necessary to avoid ">>" in nested templates 2014-08-16 05:42:39 +02:00
Nebuleon Fumika
891525aa94 Fix dynamic allocation of IconButton instances
Previously, IconButton instances to be added to button boxes were
allocated with new, but never freed with delete.

unique_ptr makes sure the buttons will be freed along with the button
box that owns them, or when code calls ButtonBox::clear.

The destructor of ButtonBox has been made redundant by this change, so
it's gone.
2014-08-16 05:17:31 +02:00
Maarten ter Huurne
004c41e2ef Simplify bottom bar button drawing in Selector
Put the drawButton calls left-to-right.
Avoid duplicate code.

The order was changed: "Select" is now always first, to be consistent
with other dialogs.
2014-08-15 18:53:08 +02:00
Maarten ter Huurne
3df841c150 Handle labelless icon positioning in GMenu2X::drawButton(Right)
Instead of correcting the returned coordinate with "- 10" externally,
omit the white space inside the methods.

Note that Font::getTextWidth, which was used until recently, considers
an empty string to have width 1, so 3 + getTextWidth("") + 6 == 10.

There is a difference in how buttons that have neither a label nor an
icon are positioned in the new code, but that is a situation that
should not occur in practice. Plus I'd argue that the new behavior is
actually better in that case.
2014-08-15 18:49:58 +02:00
Maarten ter Huurne
45304052cd Changed icon lookup in GMenu2X::drawButton(Right)
Look up the icon with the "skin:" prefix to be consistent with how
other lookups of the same icons are performed. Also don't perform
repeated lookups.
2014-08-15 17:59:55 +02:00
Maarten ter Huurne
8e885bc2c1 Removed GMenu2X::drawButton variant
This was only called form ButtonBox, so I moved the code there.

I still think a paint method shouldn't be repositioning widgets, but
that's something for a later cleanup.
2014-08-15 17:27:09 +02:00
Maarten ter Huurne
faf0287cf5 Simplify code to reload section icons when skin changes 2014-08-15 16:54:30 +02:00
Maarten ter Huurne
c1d57b62de In GMenu2X::drawButton, don't build a rectangle if we only need width 2014-08-15 16:35:24 +02:00
Maarten ter Huurne
b202f1949a Minor optimizations in Menu
Use emplace_back when a new string is put into a vector.
Removed unused variables.
When searching section names, compare C++ string to C string, so we
don't need to construct a C++ string for the second string just for
the search.
2014-08-15 14:27:05 +02:00
Maarten ter Huurne
739a9463be Don't use string::compare if there are better alternatives
When comparing full strings, operator== will do nicely.
When comparing the first char, "s[0] == c" is more efficient if we know
the string cannot be empty.
2014-08-15 14:19:17 +02:00
Maarten ter Huurne
6e8491abee Don't use (void) for empty argument list
This is necessary in C, but unusual in C++.
2014-08-15 14:01:11 +02:00
Maarten ter Huurne
d66ca947c4 Store Menu's Monitors in unique_ptrs
This results in a small code reduction and some ease of mind.
2014-08-15 13:56:20 +02:00
Maarten ter Huurne
7134eb3778 Store "bgmain" in the GMenu2X object instead of in SurfaceCollection
Since this surface is created by initBG instead of loaded from skin
search paths, it didn't really fit in SurfaceCollection. After removing
it, one of SurfaceCollection's methods could be removed as well.
2014-08-15 04:03:00 +02:00
Maarten ter Huurne
ab7a4c1cf7 Have Font::write return the width of the drawn text
This avoids having to do separate getTextWidth calls in several places.

More getTextWidth calls could be saved by splitting the rendering of
the font to an off-screen buffer from the final composition onto the
destination surface: the routines that draw text inside a box have to
compute the width before they can draw the box and currently the box
has to be drawn before the text.
2014-08-15 03:32:32 +02:00
Maarten ter Huurne
6895ac0b54 Removed static version of SurfaceCollection::getSkinFilePath
There were no external callers anymore.
2014-08-15 01:46:35 +02:00
Maarten ter Huurne
c8ea974f51 Fixed compile error on platforms where ENABLE_CPUFREQ is defined 2014-08-15 01:41:20 +02:00
Maarten ter Huurne
02384c8e72 Removed skin lookup feature from OffscreenSurface::loadImage
Instead, make the caller perform the lookup. This simplifies the
interface of loadImage and it removes the dependency from
OffscreenSurface on SurfaceCollection.
2014-08-15 01:34:35 +02:00
Maarten ter Huurne
2c47515321 Explicitly enable screen when PowerSaver exits
In theory the timer could expire between the button press that starts
the application launch and the moment the PowerSaver destructor runs.
And I think this does in fact happen occasionally thanks to the CPU
hogging SD controller driver on the GCW Zero, leading to an application
launching with a blanked screen.
2014-08-14 09:51:51 +02:00
Maarten ter Huurne
c1689e41fb Dismantled Singleton pattern of PowerSaver
The instance-on-demand didn't really work, since we needed explicit
control over this object's destruction to ensure the timer is stopped
when launching an application. And trying to combine getInstance() with
explicit external delete was just ugly.
2014-08-14 09:47:05 +02:00
Maarten ter Huurne
8d662c95f6 Various cleanups in PowerSaver
Use nullptr instead of NULL, evaluate pointer as bool where possible.
Declare the timer callback as a friend function so the methods it uses
can stay private.
Initialize screenState to false; was uninitialized which means that
an initially blanked screen might not be unblanked.
Force screen enable in constructor instead of when timeout is set.
Add removeScreenTimer method.
Include C++-ified versions of the C headers.
2014-08-14 09:28:41 +02:00
Maarten ter Huurne
6a2a0969f3 Set close-on-exec flag on inotify file descriptor 2014-08-14 07:30:33 +02:00
Maarten ter Huurne
47d349f78b Simplified file extension filtering code
Don't create any temporary strings, just use the d_name field and
strcasecmp.
2014-08-14 06:43:37 +02:00
Maarten ter Huurne
404b2a1029 Use proper feature test macro for d_type support 2014-08-14 06:10:55 +02:00
Maarten ter Huurne
56beec0895 Convert file name to C++ string as late as possible
This avoids copying the string if the file is rejected because its
category (directory or regular file) is disabled.
2014-08-14 05:30:31 +02:00
Maarten ter Huurne
b6f6bb387c Skip stat() call when the d_type field can tell us the file type
This is a BSD extension also present in glibc and uClibc. Not all libc
implementations and not all file systems support it, so we keep the
stat-based code as a fallback.
2014-08-14 05:25:26 +02:00
Maarten ter Huurne
a505d3e494 Removed FileLister::insertFile
This was a nasty hack to insert English into the list of translations.
Instead of modifying the scan results, make a copy and modify the copy.
2014-08-14 05:08:36 +02:00
Maarten ter Huurne
85b072ca43 Removed FileLister::at
In the STL, 'at' will perform range checking while operator[] will not.
Since GMenu2X doesn't use exceptions, range checking is not possible,
so 'at' and operator[] were identical.
2014-08-14 05:02:24 +02:00
Maarten ter Huurne
ba47744a52 Put trivial FileLister method implementations in header
This cuts a few hundred bytes off the stripped binary size.
2014-08-14 04:59:07 +02:00
Maarten ter Huurne
eb3def19ea Replaced generic exclude mechanism by updir filter in FileLister
The exclude mechanism was only used to filter out ".." for the skins
lister, so this lighter filter does all we need.
2014-08-14 04:45:26 +02:00
Nebuleon Fumika
d51fbb8716 Properly save the value of Selector Browser after editing a link 2014-08-14 02:12:06 +02:00
Maarten ter Huurne
60aaf5954a Show a file selector in OPK links only if Exec requires a file
Previously, if a user installed a new version of an OPK with the same
name as one that had a link configuration file, GMenu2X could request
a file for an application whose new version required no files to
launch.

In practice, this transition would occur only once per OPK application,
when its developer decided to use a custom browser after having used
GMenu2X's file browser. This bug would then show GMenu2X's file browser
to request a file that would not even be passed to the application.

Thanks to Nebuleon for analyzing the problem and the above description.
2014-08-14 02:08:51 +02:00
Maarten ter Huurne
35724170f8 Make FileLister::browse not log a non-existing directory as an error
To avoid unnecessary existence checks, we consider browsing a
non-existing directory to be a normal situation.
2014-08-13 22:59:13 +02:00
Nebuleon Fumika
f85ef14b3e Remove unnecessary file existence check in WallpaperDialog::exec()
Browsing the user's wallpaper directory will simply add no new files
to the list of wallpapers available if the directory doesn't exist.
WallpaperDialog::exec doesn't need to care about that.

Because wallpapers are files, not directories, also don't return
directories in the result. The code that makes the wallpapers list
calls FileLister::getFiles and ignores directories anyway.
2014-08-13 22:51:56 +02:00
Nebuleon Fumika
cf896e6175 Remove unnecessary file existence check in GMenu2X::showSettings()
Browsing the user's translations directory will simply add no new files
to the list of translations available if the directory doesn't exist.
GMenu2X::showSettings() doesn't need to care about that.

Because translations are files, not directories, also don't return
directories in the result. The code that makes the translations list
calls FileLister::getFiles and ignores directories anyway.
2014-08-13 22:50:16 +02:00
Nebuleon Fumika
a60a529de6 Remove unnecessary file existence check in GMenu2X::writeSkinConfig
mkdir is able to return an error code in errno to indicate that the
directory requested to be created already exists (EEXIST).
2014-08-13 22:44:43 +02:00
Nebuleon Fumika
8cd3ab8cb8 Remove unnecessary file existence check in GMenu2X::readTmp()
A file existence check is already performed, atomically with respect to
the filesystem, by ifstream's constructor. The result of this check is
available using ifstream::is_open().
2014-08-13 22:43:41 +02:00