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

786 Commits

Author SHA1 Message Date
Maarten ter Huurne
956a9b6429 Pass file name as std::string to readFileAsString
For consistency, use C++ strings as much as possible in interfaces.
2014-08-18 14:22:18 +02:00
Maarten ter Huurne
07eefb219f If an app settings file is empty, remove it
Since only non-default values are saved, it was quite likely settings
files were empty, especially since the clock saving was fixed. We now
remove a settings file on save if the contents are empty, so we have
to load fewer files on startup.
2014-08-18 12:51:21 +02:00
Maarten ter Huurne
23205dc7e6 Removed redundant exists check from Menu::openPackagesFromDir 2014-08-18 11:44:45 +02:00
Maarten ter Huurne
98f15d7419 Implement fileExists() using access() instead of open/close 2014-08-18 11:35:40 +02:00
Maarten ter Huurne
d82ebce770 Create LinkApp objects in Menu::readLinksOfSection()
This avoids having to store the paths in an intermediate vector. Also
it allows us to do the writability check once per directory instead of
once per file.
2014-08-17 22:23:17 +02:00
Maarten ter Huurne
e39447ee64 Have Menu::readLinks() sort using orderLinks()
Previously, it sorted before Link instances were created. Using
readLinks() ensures consistency and it might be more efficient if
a significant number of link files are rejected.

Also modernized the body of orderLinks() and removed unnecessary
special case for 1-link sections.
2014-08-17 22:02:33 +02:00
Maarten ter Huurne
3694deecf6 Be resilient against zero or multiple "Categories" OPK metadata keys
For zero keys, the OPK file itself would be parsed as a settings file.
For multiple keys, all first categories would be appended to the path,
leading to a much too deep directory.
2014-08-17 20:37:15 +02:00
Maarten ter Huurne
7992d83e10 Pass C++ string to LinkApp constructor
All callers already had C++ strings and LinkApp wants a C++ string,
but because of the argument type the strings had to be converted.
2014-08-17 18:52:18 +02:00
Maarten ter Huurne
79ef176831 Disable delete context menu option for undeletable link files
Before this change, it was possible to delete for example a link that
is stored on a read-only file system and it would disappear after
deletion but reappear as soon as the menu restarts.
2014-08-17 18:43:02 +02:00
Maarten ter Huurne
c3df9c4517 Removed ".empty" files for non-empty directories
Git doesn't track directories, just files, so dummy files are necessary
to preserve empty directories. These directories were not empty though.
Removing the dummy files avoids GMenu2X scanning them on startup.
2014-08-17 17:12:33 +02:00
Maarten ter Huurne
fe0c7c2e8d When going up a level in the selector, put cursor on old dir
This adds a sense of continuity to the navigation.
2014-08-17 11:15:21 +02:00
Maarten ter Huurne
bb30dedd09 When selector goes up from the root directory, stay in the root
Previously the selector would exit, but I don't see the logic in that.
2014-08-17 10:25:28 +02:00
Maarten ter Huurne
ba09d2599d Avoid out-of-range lookup when FileLister::browse is passed empty string
When the path is the empty string, it is handled as the current working
directory, which is consistent with how relative paths are handled.
2014-08-17 10:22:09 +02:00
Maarten ter Huurne
20725fcdda Do not list ".." as a subdirectory of the root directory
In Linux "/.." exists and loops back onto the root. But for the user
it is confusing to see a ".." entry listed that does nothing when
selected, so hide it.
2014-08-17 10:20:22 +02:00
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