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

803 Commits

Author SHA1 Message Date
Alexandre Vicenzi
289d0e7644 Added Brazilian Portuguese translation 2014-08-29 02:15:31 +02:00
Paul Cercueil
8364e11898 Fix extremely rare and extremely weird bug
Under certain conditions, it was possible to get orderLinks() trigger a
segmentation fault or a SIGBUS; even if all the Link* and Linkapp*
pointers where correct, the compare_links() function would eventually
end up receiving an invalid pointer.

Apparently, the std::sort function *requires* that the assertion
compare_links(a, b) != compare_links(b, a) is always true, which was not
the case previously when a link was compared with itself.
2014-08-21 04:18:50 +02:00
Maarten ter Huurne
7b2c26cc3c Don't apply realpath() to entered subdirs in Selector
This way, symlinks stay in the path, so when we go up a level we end
up in the previous directory instead of in the linked directory's
parent.
2014-08-20 14:57:17 +02:00
Maarten ter Huurne
c7a5b874f1 Don't assume that all non-directories are regular files
Other types are not very likely, but if we do encounter them it is best
to just skip them.
2014-08-20 13:09:49 +02:00
Maarten ter Huurne
3eb3a8ed7a If directory entry is a symbolic link, fall back on stat()
Unlike d_type, stat() will return the type of the target of the link
rather than the link itself.
2014-08-20 13:07:11 +02:00
Nebuleon Fumika
5758209170 Fix a crasher when launching an application whose icon is corrupt
It is possible for OPK links to refer to a missing icon or to an icon
that cannot be read as a PNG file, in which cases there is no fallback
to icons/generic.png and the icon is null.

Link::paint checks for this, but LinkApp::drawLaunch did not.

Obviously it is more desirable to properly fall back, but that would be
a very big change to many areas of the code, so this is a quick fix.
2014-08-19 09:25:26 +02:00
Maarten ter Huurne
b938c41067 Provide file permissions for newly created file
Since O_CREAT is passed, we have to provide permission flags too.
2014-08-19 00:12:05 +02:00
Maarten ter Huurne
4550eebc90 Make system calls restart on signals instead of handling EINTR
This leads to simpler code and probably fewer bugs.
2014-08-18 23:49:09 +02:00
Maarten ter Huurne
482bd09d78 Avoid rewriting non-editable app settings
This is a workaround, see TODO in code for details.
2014-08-18 23:41:53 +02:00
Maarten ter Huurne
e827b2f18c For now, consider non-deletable applications to be immutable
In the future, we could make them editable by saving a companion file
in the home directory, similar to how OPKs can be customized.
2014-08-18 23:25:57 +02:00
Maarten ter Huurne
5805d7889f Don't use file system write permissions to determine "deletable"
Instead, consider the installation location non-deletable and the home
directory deletable. This makes the "deletable" property follow the
purpose of the directory rather than its implementation details.
2014-08-18 23:17:27 +02:00
Maarten ter Huurne
fe790b1c8d Improved handling of platform specific open flags
There was support for platforms without O_DIRECTORY, but O_CLOEXEC
is also Linux specific and was hardcoded, making the whole thing not
portable.
2014-08-18 23:16:36 +02:00
Maarten ter Huurne
e12c896b99 Make writeStringToFile resilient against short writes
There are various situations in which write() might write less than
the requested amount. In that case, if any progress was made (more
than 0 bytes written), try again, otherwise consider it an error.

Thanks to Nebuleon for reviewing.
2014-08-18 22:51:58 +02:00
Maarten ter Huurne
104d749513 Don't start Monitor on non-existant paths
The check I removed earlier today was redundant for readPackages() but
not so much for the Monitor: it starts a thread and it logs an error,
both of which are better avoided when possible.

Also cleaned up implementation of readPackages() a bit.
2014-08-18 16:42:02 +02:00
Maarten ter Huurne
4740e274ed Add more detail in error message from Monitor::run() 2014-08-18 16:29:18 +02:00
Maarten ter Huurne
9f1827dc24 Make app setting file writes durable
The atomic write replaces the old with the new file, but unless we sync
the parent directory, that replacement is not permanent yet.
2014-08-18 15:56:14 +02:00
Maarten ter Huurne
fc4582a61f Write app settings files atomically
This is safer than the original code, which didn't use a temporary file
and could therefore leave partial files. Also it avoids a full sync(),
which can take a long time if for example a big file transfer is going
on or recently ended.
2014-08-18 15:35:56 +02:00
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