Compare commits

...

409 Commits
0.5.4 ... 0.6.6

Author SHA1 Message Date
Jonas Kvinge
d870ef0bd5 Release 0.6.6 2019-11-09 17:21:08 +01:00
Jonas Kvinge
53d308dac5 Exclude .github dir in maketarball.sh 2019-11-09 17:16:18 +01:00
Jonas Kvinge
89b06ae7c7 Mulitply samples by channels, dont hardcode to 2 2019-11-09 16:34:17 +01:00
Jonas Kvinge
d38485a8ad Update Changelog 2019-11-09 16:30:23 +01:00
Jonas Kvinge
834877c503 Refactor gstreamer engine code, equalizer and fix stereo balancer 2019-11-08 23:07:21 +01:00
Jonas Kvinge
d033b79af4 Remove exclusive for wasapisink
Fixes #283
2019-11-07 20:26:25 +01:00
Jonas Kvinge
daec2cc203 Remove g_type_init 2019-11-06 21:53:27 +01:00
Jonas Kvinge
4e593cebab Add const 2019-11-06 21:53:09 +01:00
Jonas Kvinge
73d7701e94 Update FUNDING.yml 2019-11-05 19:38:46 +01:00
Strawbs Bot
24f1d7a72f Update translations 2019-11-04 01:07:14 +01:00
Jonas Kvinge
6387a01d7b Fix updating compilations
Fixes #288
2019-11-03 23:23:04 +01:00
Jonas Kvinge
e838840548 Remove duplicate check 2019-11-03 19:56:10 +01:00
Jonas Kvinge
6a430b441e Remove debug line 2019-11-03 19:56:01 +01:00
Jonas Kvinge
7b977ea839 Rename EngineDevice --> DeviceFinders, Add MMDeviceFinder 2019-11-03 19:53:08 +01:00
Jonas Kvinge
62b8521cbe Update Changelog 2019-10-29 19:27:03 +01:00
Martin Delille
308244d901 Change email (#287)
I didn't noticed you mention me in the *About...* section. Thank you for that even if it is an oversized thank you for the contributions made! : sweat_smile:

I just update it to my personal address.
2019-10-29 19:12:29 +01:00
Jonas Kvinge
6f521183f9 Fix spelling 2019-10-28 20:20:13 +01:00
Jonas Kvinge
76c6f7e733 Update README.md 2019-10-28 20:06:22 +01:00
Strawbs Bot
80ebfbeb6b Update translations 2019-10-28 01:02:39 +01:00
Jonas Kvinge
793901b319 Revert accidental change to flac test file 2019-10-28 00:05:29 +01:00
Jonas Kvinge
3950df8ec9 Add libgstwasapi.dll to nsi 2019-10-27 23:55:03 +01:00
Jonas Kvinge
e800b236aa Simplify the pipeline
Fix issue where bitrate is updated incorrectly by stream discoverer
Fixes issue #282
Also make it possible to enable stereo balancer without enabling the
equalizer
2019-10-27 23:48:54 +01:00
Jonas Kvinge
4ab7871106 Add wasapisink to directsound devicefinder 2019-10-27 23:47:28 +01:00
Jonas Kvinge
3de85549b6 Add option to automatically select current playing track 2019-10-27 02:11:51 +01:00
Jonas Kvinge
73164f7182 Update scrobble point when song is restarted 2019-10-27 02:09:34 +01:00
Strawbs Bot
004b000890 Update translations 2019-10-21 01:23:16 +02:00
Jonas Kvinge
d9c703d944 Add gst/audio/audio.h include 2019-10-20 20:04:23 +02:00
Jonas Kvinge
364b650033 Convert S32LE to S16LE for analyzer 2019-10-20 18:52:58 +02:00
Jonas Kvinge
156eb874db Fix analyzer and cleanup old pipeline code
- Move HandoffCallback to audio queue
- Add new callback for detecting source format
- Remove old decodebin stuff
2019-10-20 02:56:47 +02:00
Strawbs Bot
1a28dd0311 Update translations 2019-10-20 01:24:47 +02:00
Jonas Kvinge
e29b4b8609 Add more alternative icon names 2019-10-20 01:11:40 +02:00
Jonas Kvinge
c02997e6d9 More icon fixes 2019-10-20 00:59:22 +02:00
Jonas Kvinge
7c9fc91af9 Enable system theme icons, add iconmapper and rename some icon names 2019-10-20 00:17:28 +02:00
Jonas Kvinge
cf5198ac64 Limit tagreader workers to 2 2019-10-19 15:09:18 +02:00
Strawbs Bot
e76ddd6dd2 Update translations 2019-10-19 14:56:24 +02:00
Jonas Kvinge
e3a4cf1cf5 Add option to prefer album artist when sending scrobbles
Fixes #274
2019-10-19 02:56:23 +02:00
Jonas Kvinge
5844616ea8 Only ignore closeEvent when minimizing to system tray
Fixes #277
2019-10-19 02:21:20 +02:00
Jonas Kvinge
abeb580228 Disable analyzer for other bit depths than 16
This removes the splitting of the pipeline with the tee.
Move HandoffCallback to the source, which makes it possible to convert the audio buffer in HandoffCallback later.
Until then just disable analyzer for other formats.

Removes tee and probe queue converter and sink
2019-10-19 01:45:24 +02:00
Ike Devolder
4d888dfce8 subsonic: change disc to discNumber (#278)
As found in the v1.13.0 xsd, the disc is named discNumber in the api,
currently there is a check for disc which will never be found in the
response.

@see http://www.subsonic.org/pages/inc/api/schema/subsonic-rest-api-1.13.0.xsd

Signed-off-by: BlackEagle <ike.devolder@gmail.com>
2019-10-17 17:06:30 +02:00
Jonas Kvinge
08ff6f0ede Only use gcc 2019-10-13 00:17:01 +02:00
Jonas Kvinge
c458c27231 Switch to opensuse leap 15.1 2019-10-12 23:49:41 +02:00
Jonas Kvinge
9821b70c38 Dont use gst_caps_to_string as it causes hang with some formats 2019-10-12 01:58:01 +02:00
Jonas Kvinge
8ab8401110 Update libprotobuf in nsi 2019-10-06 17:53:00 +02:00
Strawbs Bot
4f798c85cf Update translations 2019-10-05 01:01:44 +02:00
Jonas Kvinge
1949bdb43f Merge branch 'master' of github.com:jonaski/strawberry 2019-10-04 17:09:08 +02:00
Jonas Kvinge
8cf2e6b31b Remove all lines in settings 2019-10-04 17:08:35 +02:00
Jonas Kvinge
b1069f9f18 Disable use system icons option 2019-10-04 17:08:12 +02:00
Strawbs Bot
fb8dfa9ae9 Update translations 2019-10-04 01:07:02 +02:00
Jonas Kvinge
4402a56e94 Fix compile with optional components disabled 2019-10-03 23:29:52 +02:00
Jonas Kvinge
f449808ba3 Fix: imobiledevice depends on libgpod enabled 2019-10-03 22:54:40 +02:00
Jonas Kvinge
5599739433 Fix lowercased playlist album artist column
Fixes #275
2019-10-03 18:25:50 +02:00
Jonas Kvinge
197cf85f56 Turn back git revision 2019-10-01 21:42:08 +02:00
Jonas Kvinge
8c039c9c8b Release 0.6.5 2019-09-30 22:05:42 +02:00
Jonas Kvinge
c1d9bc046d Change context default 2019-09-30 22:05:03 +02:00
Jonas Kvinge
cd99fac7ed Fix OSD Pretty upper left (0,0) position and positioning on Windows
Fixes #269
2019-09-30 20:32:34 +02:00
Jonas Kvinge
f4489e6807 No need to initialize SimpleMetaBundle here 2019-09-30 20:31:18 +02:00
Jonas Kvinge
f2078271b6 Only update scrobble point in SetStreamMetadata when length is changed 2019-09-30 18:58:55 +02:00
Jonas Kvinge
a3ae9acebb Listenbrainz: don't send "various artists" as artist 2019-09-29 13:50:24 +02:00
Jonas Kvinge
b0580265ca Listenbrainz: don't send "various artists" as album artist
Fixes #273
2019-09-29 13:31:46 +02:00
Jonas Kvinge
b4f012392a Fix full validation of appdata file
Fixes #271
2019-09-29 13:29:52 +02:00
Jonas Kvinge
1598809f55 Fix OSD reposition image 2019-09-25 19:01:55 +02:00
Jonas Kvinge
6d4f7aa61f Turn back git revision 2019-09-25 18:54:22 +02:00
Jonas Kvinge
382080ae4e Release 0.6.4 2019-09-25 13:54:16 +02:00
Strawbs Bot
66ac529bca Update translations 2019-09-25 12:01:08 +02:00
Jonas Kvinge
ab72207027 Change domain 2019-09-24 00:06:37 +02:00
Jonas Kvinge
e3aebf1ca2 Update maketarball.sh.in 2019-09-23 22:23:30 +02:00
Jonas Kvinge
0e5820c038 Update file types 2019-09-23 21:52:48 +02:00
Jonas Kvinge
780e4d34df Update Changelog 2019-09-23 21:32:56 +02:00
Jonas Kvinge
a8700572b7 Allow empty artist and album in Subsonic song replies
Fixes #266
2019-09-23 19:20:11 +02:00
Jonas Kvinge
055516312a Fix signature in Qobuz stream url request
Fixes #267
2019-09-23 19:18:12 +02:00
Jonas Kvinge
76b4a6585e Update copyrights 2019-09-23 19:17:41 +02:00
Jonas Kvinge
b57535c5ad Make gstreamer discoverer handle next url too 2019-09-23 01:03:03 +02:00
Jonas Kvinge
eb10a15eee Reset next item temporary metadata 2019-09-23 01:00:55 +02:00
Jonas Kvinge
30ed362a8c Increase preload gap 2019-09-23 01:00:27 +02:00
Jonas Kvinge
34f071ed1d Change conflicting variable 2019-09-23 00:34:29 +02:00
Jonas Kvinge
3d3d641e1c Fix player not using preloaded stream url breaking gapless playback
Fixes #26
2019-09-22 22:47:07 +02:00
Jonas Kvinge
10c11f2c3d Fix compile on older Qt than 5.11 2019-09-22 22:43:54 +02:00
Jonas Kvinge
cec2745dc0 Qobuz: Send mac address as device_manufacturer_id in login 2019-09-22 17:10:04 +02:00
Jonas Kvinge
8d15edb063 Add function to get mac address 2019-09-22 17:06:45 +02:00
Jonas Kvinge
38cf3dc141 Only set user agent if it's missing in NetworkAccessManager 2019-09-22 17:05:26 +02:00
Jonas Kvinge
c146290e07 Add function to get mac address 2019-09-22 17:04:57 +02:00
Jonas Kvinge
a1745289be Correct app id header 2019-09-21 18:54:15 +02:00
Jonas Kvinge
5a7dbfc87a qobuz: add headers to requests 2019-09-21 18:53:12 +02:00
Jonas Kvinge
f645950a8f Change all API urls to https 2019-09-20 23:22:27 +02:00
Jonas Kvinge
b273da0b5e Switch to openssl 1.1 in nsi 2019-09-20 18:49:53 +02:00
Jonas Kvinge
689f1eb0c5 Add libgiognutls.dll to nsi 2019-09-20 18:31:35 +02:00
Jonas Kvinge
b0a2edf5fa tagreader: remove use of deprecated taglib functions 2019-09-20 18:07:43 +02:00
Jonas Kvinge
e7b5e02657 Update taglib 2019-09-20 18:07:13 +02:00
Jonas Kvinge
2d4efd6cf0 Add libbrotlicommon.dll 2019-09-19 20:56:39 +02:00
Jonas Kvinge
defc0ada78 Fix compile warnings 2019-09-19 17:44:14 +02:00
Jonas Kvinge
2f3f4f609c Rename libbrotlidec-0.dll to libbrotlidec.dll 2019-09-19 17:24:49 +02:00
Jonas Kvinge
4a9c9f8cd4 gstreamer: disconnect callbacks, avoid gst_discoverer_stop 2019-09-17 22:42:51 +02:00
Jonas Kvinge
bdc089290d Add fallthrough comments and remove -Wimplicit-fallthrough=0
Signed-off-by: Jonas Kvinge <jonas@jkvinge.net>
2019-09-16 21:20:12 +02:00
Strawbs Bot
cf9f48d8da Update translations 2019-09-16 20:57:06 +02:00
Jonas Kvinge
2d67279180 Fix minor code issues 2019-09-15 20:27:32 +02:00
Jonas Kvinge
83e10aac27 Fix exiting macos devicelister 2019-09-15 01:12:05 +02:00
Jonas Kvinge
9972124aa1 Add gstreamer plugins to macdeploy.py 2019-09-14 20:30:06 +02:00
Jonas Kvinge
d0eb1ba96e Avoid gst_discoverer_stop on all OSes except Linux 2019-09-14 20:11:29 +02:00
Jonas Kvinge
f5d2910638 Add libbrotlidec-0.dll and libpsl-5.dll to nsi 2019-09-12 20:38:13 +02:00
Jonas Kvinge
1cafaf3a79 Disable video for playbin 2019-09-12 18:07:10 +02:00
Jonas Kvinge
fccc133cb2 Update gstreamer plugins in nsi 2019-09-11 21:00:44 +02:00
Jonas Kvinge
9fb50b8a73 Update taglib 2019-09-11 00:36:03 +02:00
Jonas Kvinge
c66c1e17d3 Make gstreamer pipeline detect filetype 2019-09-09 22:11:13 +02:00
Jonas Kvinge
4496760340 Dont search for lyrics if tags are empty 2019-09-09 21:48:22 +02:00
Jonas Kvinge
506200d2ee Update supported audio in README 2019-09-09 21:47:54 +02:00
Jonas Kvinge
04898a3b01 Add Ogg Vorbis test audio file 2019-09-09 21:47:39 +02:00
Jonas Kvinge
f67fb53308 Fix conflicting variable 2019-09-09 18:17:56 +02:00
Jonas Kvinge
c5b78dde04 Convert remaining foreach to C++11 for loops 2019-09-09 00:53:05 +02:00
Jonas Kvinge
57d9c87de6 Replace NULL with nullptr 2019-09-08 21:18:26 +02:00
Jonas Kvinge
795f95d855 Add gstreamer stream discoverer workaround for Windows
- gst_discoverer_stop seem to block
2019-09-08 21:07:56 +02:00
Jonas Kvinge
c0ebbc8e2f Fix ampache compatibility 2019-09-08 19:46:51 +02:00
Jonas Kvinge
fb377c32ea Initialize filetype and bitrate 2019-09-08 17:36:50 +02:00
Jonas Kvinge
e13faff2d7 Add missing include for assert 2019-09-08 00:36:32 +02:00
Jonas Kvinge
b0c5348116 Remove comment 2019-09-07 23:50:36 +02:00
Jonas Kvinge
b462ec022a Remove unused variable 2019-09-07 23:50:26 +02:00
Jonas Kvinge
e45a0bf24b Add stream discoverer to gstreamer pipeline and continuous updating of bitrate 2019-09-07 23:34:13 +02:00
Jonas Kvinge
8962644ba8 Improvements to device manager
- Mount and unmount devices in lister thread
- Safely close watcher and backends for devices
- Enable abort loading device
- Fix MTP connection
2019-09-07 23:30:35 +02:00
Jonas Kvinge
ad5e04bbcc Always ignore closeEvent 2019-09-05 19:07:58 +02:00
Jonas Kvinge
6fc7baec39 Add Russian 2019-09-01 23:59:03 +02:00
Jonas Kvinge
acd49a9c40 Update translations 2019-09-01 18:00:04 +02:00
Jonas Kvinge
bf04358a47 Replace media buttons 2019-08-29 22:11:22 +02:00
Jonas Kvinge
b7e13c7b86 Fix windows thumbbar 2019-08-29 21:32:52 +02:00
Jonas Kvinge
9b45f0661e Add option to bundle gstreamer plugins on Linux 2019-08-27 22:29:48 +02:00
Jonas Kvinge
2a61b1202b Set subsonic API version to 1.13.0 2019-08-27 17:26:49 +02:00
Jonas Kvinge
114f862ea4 TagLib MP4 - setTrack()/setYear() accepts 0 to remove the tag 2019-08-26 23:50:14 +02:00
Jonas Kvinge
5a490a8b5a SingleApplication: Fallback to qgetenv for username on Windows too 2019-08-26 17:31:49 +02:00
Jonas Kvinge
8fdc1c1b21 SingleApplication: Use initialization list 2019-08-26 17:22:11 +02:00
Jonas Kvinge
32cac90720 SingleApplication: Remove debug output of username 2019-08-26 02:18:02 +02:00
Jonas Kvinge
b2160255d3 SingleApplication: Use geteuid / getpwuid to get username and reformat
sources
2019-08-26 02:00:47 +02:00
Jonas Kvinge
7fe1f4de93 Fix compile on OpenBSD 2019-08-26 01:37:22 +02:00
Jonas Kvinge
1fbb1b1524 Keep original window size when restoring from system tray 2019-08-23 20:43:58 +02:00
Jonas Kvinge
0105a53765 Use qgetenv instead of QProcess/whoami to get username 2019-08-22 21:38:54 +02:00
Jonas Kvinge
bd5ab80276 Use FollowRedirectsAttribute everywhere 2019-08-22 19:28:54 +02:00
Jonas Kvinge
387d790228 Fix spelling in contributor variables in about 2019-08-22 18:49:03 +02:00
Jonas Kvinge
d199a2be0d Fix typos and spelling 2019-08-22 18:45:32 +02:00
Jonas Kvinge
f81ecffda6 Don't treat songs with different album as duplicates 2019-08-21 20:46:08 +02:00
Jonas Kvinge
882f80de1e Add FollowRedirectsAttribute 2019-08-21 00:01:38 +02:00
Jonas Kvinge
4359f2a0ce Follow redirects in subsonic 2019-08-20 23:32:20 +02:00
Jonas Kvinge
9c485c4d94 Split NetworkTimeouts and RedirectFollower to it's own files
- Follow redirects by default
2019-08-20 23:31:23 +02:00
Jonas Kvinge
1330197036 Small subsonic changes
- Follow redirect in subsonic ping test
- Reset networkaccessmanager to make verify certificate setting take
affect immediately
2019-08-20 12:33:01 +02:00
Jonas Kvinge
0b0d5fa227 Add back libgstlame in macdeploy 2019-08-18 22:08:32 +02:00
Jonas Kvinge
45424b8a52 Change CFBundleIdentifier 2019-08-18 01:00:47 +02:00
Jonas Kvinge
0956acbdfb Add missing comma 2019-08-17 01:04:48 +02:00
Jonas Kvinge
654f553d8f Move InformOfCurrentSongChange() to fix crash when active playlist item
is reset
2019-08-17 00:52:29 +02:00
Jonas Kvinge
e4b6e20db6 Turn playlist glow effect off by default on macOS 2019-08-17 00:00:12 +02:00
Jonas Kvinge
b4f6c6f869 Include NSWindow in mac_startup.mm 2019-08-16 22:52:50 +02:00
Jonas Kvinge
16edc52bae Fix deprecated macOS key modifiers 2019-08-16 22:27:48 +02:00
Jonas Kvinge
a33e6c03e4 Use QPixmap::toImage() and QImage.toCGImage() instead 2019-08-16 22:26:30 +02:00
Jonas Kvinge
4dccb40bf9 Add missing uninstall for xine plugins in nsi 2019-08-14 23:29:44 +02:00
Jonas Kvinge
9ce1981f93 Fix copyright in iconloader 2019-08-14 23:28:55 +02:00
Jonas Kvinge
6374c77aa8 Read Json error when possible 2019-08-12 22:24:05 +02:00
Jonas Kvinge
871bb391d6 Add lyrics from lololyrics.com 2019-08-12 22:06:01 +02:00
Jonas Kvinge
c3903a7b35 Add lyrics from lyrics.ovh 2019-08-12 18:11:01 +02:00
Jonas Kvinge
6aabf82c11 Update issue templates 2019-08-11 23:33:15 +02:00
Jonas Kvinge
89b624aadf Update issue templates 2019-08-11 23:27:46 +02:00
Jonas Kvinge
67317292ee Create FUNDING.yml 2019-08-11 23:11:26 +02:00
Jonas Kvinge
42e7f64856 Make marking songs unavailable optional 2019-08-11 22:30:28 +02:00
Jonas Kvinge
79d963fd65 Change variable name 2019-08-11 22:29:02 +02:00
Jonas Kvinge
44649fd950 Remove remaining references to SPMediaKeyTap 2019-08-11 21:06:25 +02:00
Martin Delille
0e97f99f93 remove 3rdparty SPMediaKeyTap (#239) 2019-08-11 20:44:32 +02:00
Jonas Kvinge
4f52ceb3e0 Make fancy tabbar background color configurable 2019-08-08 23:16:45 +02:00
Jonas Kvinge
61253b5551 Update taglib 2019-08-07 19:29:40 +02:00
llucps
12bd6f0d9b Enable About Strawberry and QT menu on macOS (#237)
* Enable About Strawberry and QT menu on macOS

* Enable About Strawberry and QT menu on macOS
2019-08-07 18:26:11 +02:00
SamTShaw
a32010e03b Ipod Playlist Support (#220)
* Ipod Playlist Support

Copy a whole playlist to the ipod and create an entry in Playlists on
the iPod

* Fix formatting and indentation

Fix indenting and formatting to be consistent
2019-08-07 17:13:40 +02:00
Jonas Kvinge
4a934c9dab Remove use of some deprecated code and cleanup other macOS code 2019-08-06 20:31:54 +02:00
Jonas Kvinge
20766c1feb Fix systemtray icon on macOS 2019-08-06 20:31:31 +02:00
Jonas Kvinge
6cd4de548f Turn back git revision 2019-08-06 15:17:31 +02:00
Jonas Kvinge
8ac4dea8f1 Release 0.6.3 2019-08-05 23:26:19 +02:00
Jonas Kvinge
e8af3e8d3c Simplify if statement 2019-08-05 23:03:40 +02:00
Jonas Kvinge
cd05b10168 Remove extra debugging 2019-08-05 23:03:04 +02:00
Jonas Kvinge
140935bd8c Add album - disc grouping 2019-08-05 19:17:31 +02:00
Jonas Kvinge
ecb122d93c Make collection watcher unwatch removed directories
Fixes #233
2019-08-05 18:40:47 +02:00
Jonas Kvinge
c6e08e0039 Fix crash in internet services 2019-08-05 18:38:27 +02:00
Jonas Kvinge
be1e14df81 Fix musicbrainz tagfetcher 2019-08-04 16:02:22 +02:00
Jonas Kvinge
28bca261fb Fix mageia rpm suffix 2019-08-04 03:16:30 +02:00
Jonas Kvinge
2ab5bc1ad2 Turn back git revision 2019-08-04 03:16:08 +02:00
Jonas Kvinge
10c57cf6da Release 0.6.2 2019-08-03 13:57:54 +02:00
Jonas Kvinge
e65c5eeab1 Release 0.6.1 2019-08-03 13:29:22 +02:00
Jonas Kvinge
85fad35dc2 Update README.md 2019-08-03 13:15:43 +02:00
Jonas Kvinge
c992768efe Remove ChartLyrics (service is down) 2019-08-03 13:08:14 +02:00
Jonas Kvinge
7b13c0d059 Fix watching new subdirs in collection watcher 2019-08-02 23:58:47 +02:00
Jonas Kvinge
2d3f41da6f Automatically remove devices with old schemas when upgrading 2019-08-02 22:58:30 +02:00
Jonas Kvinge
43b9941dc8 Make sqlite3 fts5 check fatal 2019-08-02 21:12:18 +02:00
Jonas Kvinge
dcf27f54aa Add rpm syntax for mageia 2019-08-02 20:25:46 +02:00
Jonas Kvinge
fbf6b69e75 Update Changelog 2019-08-01 22:01:27 +02:00
Jonas Kvinge
0bfebd90da Add CMAKE_REQUIRED_FLAGS --std=c++11 to check_cxx_source_runs 2019-08-01 21:49:19 +02:00
Jonas Kvinge
e7c3dafa36 Handle a case where the playing widget is gets stuck when switch fast
between context and other widgets
2019-08-01 21:15:46 +02:00
Jonas Kvinge
e90a36da79 Fix track slider popup being stuck 2019-08-01 20:03:37 +02:00
Jonas Kvinge
93f33615ad Don't use check_cxx_source_runs when cross-compiling 2019-07-31 23:06:59 +02:00
Jonas Kvinge
99569081c9 Simply some song checks and make url always unique by using stream url
instead
2019-07-31 22:26:51 +02:00
Jonas Kvinge
588a0b3c41 Add cmake test for sqlite3 FTS5 2019-07-31 20:05:38 +02:00
Jonas Kvinge
4a1118ceb3 Fix macOS build 2019-07-31 20:03:24 +02:00
Jonas Kvinge
a65415bc10 Fix device schema 2019-07-30 22:56:33 +02:00
Jonas Kvinge
8a0e66bf11 Switch to FTS5 with unicode61 (#229)
* Switch to FTS5 with unicode61

* Update required sqlite version in README

* Update README

* Change back db file
2019-07-30 22:45:22 +02:00
Jonas Kvinge
02cda47c28 Disable trackslider popup on macos 2019-07-30 22:11:09 +02:00
Jonas Kvinge
d34a323a81 Handle cases where playlist background album gets stuck on error 2019-07-30 21:32:56 +02:00
Jonas Kvinge
4166ae8db0 Check HttpStatusCodeAttribute 2019-07-30 21:32:20 +02:00
Jonas Kvinge
955b906b52 Add Song() != operator 2019-07-30 21:31:26 +02:00
Jonas Kvinge
0d424aa81e Dont fetch lyrics again if only url is changed through url handler 2019-07-30 21:30:52 +02:00
Jonas Kvinge
80acbfa56a Update contributors 2019-07-30 21:30:08 +02:00
Jonas Kvinge
a7cac24004 Unref pipeline in moodbar on failure 2019-07-28 23:42:12 +02:00
Jonas Kvinge
2927bcf09d Merge branch 'master' of github.com:jonaski/strawberry 2019-07-28 14:58:52 +02:00
Jonas Kvinge
08dee6bb4f Fix error message from url handler 2019-07-28 14:58:34 +02:00
Jonas Kvinge
08c92f906a Update translations 2019-07-27 13:25:51 +02:00
Jonas Kvinge
8e9c9802d1 Change new line to unix 2019-07-27 12:34:27 +02:00
Jonas Kvinge
138df66d5e Use common nsi file 2019-07-27 12:32:28 +02:00
Jonas Kvinge
0a71347e9a Fix playlist shortcuts 2019-07-26 22:46:04 +02:00
Jonas Kvinge
2a541a7b9c Update README 2019-07-26 20:55:20 +02:00
Jonas Kvinge
705c12e8da Update README and Changelog 2019-07-26 20:52:47 +02:00
Jonas Kvinge
cf33df1339 Log system type on startup 2019-07-26 19:24:16 +02:00
Jonas Kvinge
87e543b5ef Fix collection query 2019-07-26 19:14:15 +02:00
Jonas Kvinge
81caec99b7 Fix closing databases 2019-07-25 17:56:28 +02:00
Jonas Kvinge
41484f8673 Fix exit 2019-07-24 23:29:09 +02:00
Jonas Kvinge
da0d61f36a Fix regression in playlist backend caused by previous commits 2019-07-24 21:37:09 +02:00
Jonas Kvinge
6f3bc74db0 Fix cross-compile for windows 2019-07-24 19:34:33 +02:00
Jonas Kvinge
af3bd6ec2f Use QNetworkAccessManager::supportedSchemes() 2019-07-24 19:27:00 +02:00
Jonas Kvinge
b5eb13449b Safely close database connections and delete backends
Also fix NewClosure leak caused by disconnected object signals
2019-07-24 19:16:51 +02:00
Jonas Kvinge
bd78e8c275 Fix memory leaks 2019-07-22 20:53:05 +02:00
Jonas Kvinge
2df21081a1 Fix pixmap cache in collection model
- Properly remove both from pixmap cache, pending art and pending cache keys when songs are deleted
- Increase default pixmap cache
- Clear pixmap cache when model is reset
2019-07-22 19:57:53 +02:00
Jonas Kvinge
ffebff4ea9 Fix uninitialized variable 2019-07-21 21:28:45 +02:00
Jonas Kvinge
2885bc99ca Fix memory leak in Database::BackupFile 2019-07-21 18:50:16 +02:00
Jonas Kvinge
2657b80adb Fix memory leak in tagreader 2019-07-21 15:12:28 +02:00
Jonas Kvinge
ebfc106701 Update libcdio 2019-07-21 13:19:27 +02:00
Jonas Kvinge
4d60ca951d Update Changelog 2019-07-21 00:05:54 +02:00
Jonas Kvinge
acf5c57599 Use InitArtManual in InitFromFilePartial 2019-07-20 22:53:01 +02:00
Jonas Kvinge
927df5ff39 Bump LSMinimumSystemVersion to 10.13.4 2019-07-20 15:26:36 +02:00
Jonas Kvinge
31fc031267 Fix missing qt plugins in macOS travis-ci build (#225) 2019-07-20 15:23:22 +02:00
Jonas Kvinge
02794e0ebd Add libzstd and libtasn1-6 2019-07-20 02:26:44 +02:00
Jonas Kvinge
ea6cce7068 Fix mtp device support 2019-07-19 19:56:37 +02:00
SamTShaw
e4cefeaa8f Ipod Support when listed from Udisks2 (#219)
Udisks2 didn't check to see if the device was actually an ipod, like
GIODeviceLister does.
2019-07-19 19:22:14 +02:00
Jonas Kvinge
d12d5fd8ae Update .travis.yml 2019-07-18 23:55:30 +02:00
Jonas Kvinge
0617c3fdc0 Update .travis.yml 2019-07-18 23:09:01 +02:00
Jonas Kvinge
f00eedf57e Update .travis.yml 2019-07-18 22:12:48 +02:00
Jonas Kvinge
6d36ae6197 Update .travis.yml 2019-07-18 21:35:07 +02:00
Martin Delille
45125abb8f Fix Finder icon (#216)
- Regenerate new strawberry.icns
- Fix Info.plist CFBundleIconFile
- Install Info.plist to strawberry.app
2019-07-17 23:13:15 +02:00
Jonas Kvinge
045b0cd075 Remove bogus svg 2019-07-17 22:35:19 +02:00
Martin Delille
ff3333e1bf Use create-dmg to generate MacOS release (#215) 2019-07-17 22:05:41 +02:00
Martin Delille
7663c5e149 MacOS CI improvement (#214)
* travis ci osx: simpler lib path

* Remove unnecessary sudo
2019-07-17 21:10:17 +02:00
Jonas Kvinge
4d4748a0a8 Update protobuf 2019-07-14 12:26:07 +02:00
Jonas Kvinge
f8f84ed09e Only replace non-ascii characters when not allowing extended ascii 2019-07-14 03:16:53 +02:00
Jonas Kvinge
e7de7ebbfa Use iconv to replace non-ascii characters 2019-07-14 03:08:19 +02:00
Jonas Kvinge
c9f01f4bc4 Remove old devicekit udisks backend 2019-07-13 23:00:25 +02:00
Jonas Kvinge
f2675adc05 Remove vlc, xine and phonon from deb 2019-07-13 22:52:05 +02:00
Jonas Kvinge
75beaa3684 Make sure device is valid before adding it 2019-07-13 18:28:29 +02:00
Jonas Kvinge
079495cc32 Remove usless include in cmake 2019-07-13 18:02:25 +02:00
Jonas Kvinge
c8bd89e56f Remove support for old imobiledevice uuid, it won't work anyway because
of other changes
2019-07-13 17:55:50 +02:00
Jonas Kvinge
b089ba2e04 Free memory of service descriptor and fix possible crashes 2019-07-13 17:33:58 +02:00
Jonas Kvinge
adbf8495c6 Add libgstaiff.so to macdeploy 2019-07-12 20:32:52 +02:00
Jonas Kvinge
ad062862d8 Add device url to mtp loader failure message 2019-07-12 20:32:30 +02:00
Gavin D. Howard
3a86a93154 Extend article sorting to artist and album artist (#210) 2019-07-11 16:51:25 +02:00
Jonas Kvinge
dcf0d6f72d Fix thread crash in mtpdevice 2019-07-11 00:28:19 +02:00
Jonas Kvinge
83d3725240 Fix MessageReply crash in tagreader 2019-07-10 22:40:30 +02:00
Jonas Kvinge
ce1dd69557 Change defaults in device schema 2019-07-10 20:04:05 +02:00
Jonas Kvinge
4081bdd752 Fix ctime in tagreader 2019-07-10 20:02:51 +02:00
Jonas Kvinge
c3f1e312b3 Change defaults in schemas 2019-07-10 20:02:21 +02:00
Jonas Kvinge
d820878b89 Fix oauth checkbox in tidal settings 2019-07-09 22:53:50 +02:00
Jonas Kvinge
7fa1461d5e Use QUrl::isLocalFile() 2019-07-09 21:43:56 +02:00
Jonas Kvinge
f4b1ef4d04 Set initial position of OSDPretty 2019-07-09 20:28:43 +02:00
Jonas Kvinge
656130a739 Replace QDesktopWidget in OSDPretty 2019-07-09 19:49:15 +02:00
Jonas Kvinge
aa8679dff5 Fix TryLoadPixmap and ShowCover 2019-07-09 01:14:58 +02:00
Jonas Kvinge
f94a3095fd Fix TryLoadPixmap and ShowCover 2019-07-09 01:05:42 +02:00
Jonas Kvinge
e11958dd58 Fix index in InternetSearchModel 2019-07-09 01:02:54 +02:00
Jonas Kvinge
a5a251a964 Remove use of QDesktopWidget in QSearchField 2019-07-09 00:05:08 +02:00
Jonas Kvinge
8cb1015a35 Remove use of QDesktopWidget in settingsdialog 2019-07-09 00:04:52 +02:00
Jonas Kvinge
b5dd90b2d5 Check QT_VERSION_CHECK for QImage::sizeInBytes() or QImage::byteCount() 2019-07-08 23:35:43 +02:00
Jonas Kvinge
5f7efee00e ifdef QFontMetrics::horizontalAdvance to make it work with older Qt 2019-07-08 23:27:45 +02:00
Jonas Kvinge
4150e3efde Use QT_VERSION to check whether to use QFileInfo::birthTime() or
QFileInfo::created()
2019-07-08 22:54:13 +02:00
Jonas Kvinge
8ebcb71e6e Replace all uses of QSignalMapper with lambda expressions 2019-07-08 22:27:45 +02:00
Jonas Kvinge
f3e852c042 Replace QImage::byteCount() with sizeInBytes() 2019-07-08 22:25:56 +02:00
Jonas Kvinge
5e2a07d144 Remove unused typedef 2019-07-08 22:24:47 +02:00
Jonas Kvinge
25f6231e9d Replace QString::null with QString() 2019-07-08 22:24:00 +02:00
Jonas Kvinge
beeba88ea5 Replace QModelIndex child() with index() 2019-07-08 22:23:15 +02:00
Jonas Kvinge
cc3d454d60 Add lyrics to edit tag dialog 2019-07-08 22:21:12 +02:00
Jonas Kvinge
afb583cff4 Remove unused typedef 2019-07-08 22:20:41 +02:00
Jonas Kvinge
561fa66393 Replace QFontMetrics::width with horizontalAdvance 2019-07-08 22:20:02 +02:00
Jonas Kvinge
870dc0d36f Replace QFontMetrics::width with horizontalAdvance, dark with darker, background() with window() and QString::null with QString() 2019-07-08 22:19:14 +02:00
Jonas Kvinge
51462dee1e Use QUrl::fromEncoded 2019-07-08 22:10:43 +02:00
Jonas Kvinge
c752d28c6a Change QFileInfo::created() to birthTime(), read lyrics from MP3 files 2019-07-08 22:01:34 +02:00
Jonas Kvinge
d5ca0ca283 Change compiler flags 2019-07-08 21:59:07 +02:00
Jonas Kvinge
f371b3a338 Fix tidal request 2019-07-08 17:08:10 +02:00
Jonas Kvinge
93fc4a2c86 Fix Tidal api URL 2019-07-08 08:10:52 +02:00
Jonas Kvinge
f10d3f86cc Fix Mpris2 AlbumCoverLoaded 2019-07-08 00:13:45 +02:00
Jonas Kvinge
af17b0015b Fix InitArtManual() to use album artist 2019-07-07 21:56:30 +02:00
Jonas Kvinge
61af1d1c72 Update file filter 2019-07-07 21:36:05 +02:00
Jonas Kvinge
65780e1672 Improve album cover searching and cover manager, use HttpStatusCodeAttribute and QSslError for services
- Improve album cover manager
- Change art_automatic and art_manual to QUrl
- Refresh collection album covers when new album covers are fetched
- Fix automatic album cover searching for local files outside of the collection
- Make all Json services check HttpStatusCodeAttribute
- Show detailed SSL errors for Subsonic, Tidal and Qobuz
2019-07-07 21:14:24 +02:00
Jonas Kvinge
c92a7967ea Change filename to url 2019-07-06 14:54:41 +02:00
Jonas Kvinge
60aed593b3 Fix download albumcovers setting 2019-07-06 00:16:13 +02:00
Jonas Kvinge
044f347729 Re-enable tidal oauth settings 2019-07-06 00:02:25 +02:00
Jonas Kvinge
aec9df1882 Switch to queue2 for probe queue (#204) 2019-07-05 23:50:57 +02:00
Jonas Kvinge
4f0a2515f8 Tweak the background image settings a bit
- Disable "do not cut" option when keep aspect ratio is unchecked
- Shorten text and add spacer to widget
2019-07-05 01:07:19 +02:00
Gavin D. Howard
5cde33711e Make playlist ignore articles when sorting (#202)
This is more correct, and the other way is driving me crazy.
2019-07-05 00:13:51 +02:00
Jonas Kvinge
64750025f6 Update libnettle 2019-07-04 22:51:17 +02:00
Jonas Kvinge
cd1cbfdffe Update libhogweed 2019-07-04 22:44:42 +02:00
Jonas Kvinge
d413f2c3a7 Revert "Try queue2 for probe queue"
This reverts commit a9c162476c.
2019-07-03 02:24:32 +02:00
Jonas Kvinge
ba314dd734 Set source in backends to fix losing source in InitFromFilePartial()
when updating path
2019-07-02 00:48:40 +02:00
Jonas Kvinge
9105b7615c Change to reference 2019-07-02 00:48:09 +02:00
Jonas Kvinge
a9c162476c Try queue2 for probe queue 2019-07-02 00:47:10 +02:00
Jonas Kvinge
732b37aca0 Use QMap::contains() 2019-07-01 19:20:57 +02:00
Jonas Kvinge
291b5fad7f Updated Changelog 2019-07-01 01:08:07 +02:00
Jonas Kvinge
c2a6def8b9 Rename cache album covers to download album covers and only do it for
favorite requests
2019-07-01 01:01:30 +02:00
Jonas Kvinge
9083c578cc Add live scanning (#199) 2019-06-30 21:06:07 +02:00
m4x3t
bcfd1d39bb Modify stretch background image functionality (#198)
* Modify stretch background image functionality

Changes the stretch functionality to fill out
the playlist background completely by zooming
the image (if keep aspect ratio is selected)
instead of filling it only height-wise.

* Add option to keep old background fill

* Fix playlist background image width and height

* Fix width calculation

* Remove old calculations
2019-06-30 19:37:05 +02:00
Jonas Kvinge
1185b910c4 Ops 2019-06-29 20:29:37 +02:00
Jonas Kvinge
540b6eba04 Fix hardcoded systemtray icon 2019-06-29 20:18:54 +02:00
Jonas Kvinge
47f4287e64 Merge remote-tracking branch 'origin/musicbrainz' 2019-06-29 19:58:10 +02:00
Jonas Kvinge
264c6e259b Respect rate limiting when fetching tags from musicbrainz 2019-06-29 19:57:20 +02:00
m4x3t
0bbe9838c4 Add option: notification on playback resume (#196)
* Add option: notification on playback resume

This adds an optional setting to show the
notification that is displayed when changing
the track when resuming playback as well.

* Modify resume notification calling

This adds a new signal "Resumed" that is emitted
when the player status is changed from Paused
to Playing.
The AlbumArtLoaded function will only be called
again when playback is manually resumed, and not
when the player is started for the first time
or when the track is changed.
2019-06-29 19:54:27 +02:00
Jonas Kvinge
2fe337eac3 Partial revert travis_terminate 2019-06-29 19:18:26 +02:00
Jonas Kvinge
5d7caafdf7 Terminate if one of the commands fail inside an if statement 2019-06-29 16:31:47 +02:00
Jonas Kvinge
f416ef925b Only create private key if DEPLOY_KEY_ENC is set 2019-06-29 15:57:30 +02:00
Jonas Kvinge
60bd90848b Add tests (#193) 2019-06-28 01:33:22 +02:00
Jonas Kvinge
b9f4407815 Change to const QString& 2019-06-23 18:34:03 +02:00
Jonas Kvinge
f9cd2639ff Remove annoying <year> Remaster from album and song titles 2019-06-23 18:32:15 +02:00
Jonas Kvinge
aeb36e8665 Simplify generating queries in lyrics providers 2019-06-23 16:45:00 +02:00
Jonas Kvinge
057482a3e5 Lower default search limits 2019-06-23 00:20:53 +02:00
Jonas Kvinge
15721da46e Read duration, samplerate and bit depth from stream url replies 2019-06-22 08:39:30 +02:00
Jonas Kvinge
f12b82b5ce Move checkboxes into preferences groupbox in Subsonic settings 2019-06-22 08:38:50 +02:00
Jonas Kvinge
10dc725942 Attempt to fix MessageReply crash when saving tags 2019-06-22 08:36:02 +02:00
Jonas Kvinge
5bd5cdf435 Make sure album_id is not null 2019-06-22 08:33:16 +02:00
Jonas Kvinge
84b3603c08 Fix initialization 2019-06-21 02:26:37 +02:00
Jonas Kvinge
8f59b96731 Update Changelog 2019-06-21 00:12:07 +02:00
Jonas Kvinge
e1de110dd7 Validate configuration better 2019-06-20 20:49:02 +02:00
Jonas Kvinge
8b6fd3d594 Make text selectable 2019-06-20 18:46:14 +02:00
Jonas Kvinge
d7761e8d79 Change parameters to const 2019-06-20 17:09:07 +02:00
Jonas Kvinge
751d652a2f Change title 2019-06-20 17:02:29 +02:00
Jonas Kvinge
647e7e708a Add confirmation box for opening songs in file browser 2019-06-20 17:00:10 +02:00
Jonas Kvinge
505c0eeae2 Set Unknown error if error is missing in Subsonic too 2019-06-20 16:37:37 +02:00
Jonas Kvinge
bf4001968e Change to const references, make search progress and status pass search id 2019-06-20 16:33:28 +02:00
Jonas Kvinge
9d222e2c57 Rename filename to url, change album_id to string and recreate songs tables (#182) 2019-06-20 02:14:44 +02:00
Jonas Kvinge
033300d659 Disable remove favorites from context menu in internetsongsview 2019-06-19 23:26:15 +02:00
Jonas Kvinge
4f2b04bd8f Enable login buttons when login attempt is complete 2019-06-19 23:15:15 +02:00
Jonas Kvinge
f8b9bb4b0f Remove user id and country code setting 2019-06-19 22:20:21 +02:00
Jonas Kvinge
8ce8e320c3 Change ids to qint64 2019-06-19 20:40:11 +02:00
Jonas Kvinge
7c0ab4212b Fix minor code issues with Qobuz 2019-06-19 12:57:12 +02:00
Jonas Kvinge
26633e0982 Fix compile error 2019-06-19 02:39:11 +02:00
Jonas Kvinge
d27a3f1f33 Set Subsonic API version to 1.15.0 2019-06-19 02:30:28 +02:00
Jonas Kvinge
89252d0dba Add Qobuz support (#181) 2019-06-19 02:22:11 +02:00
Jonas Kvinge
dbd2edf442 Fix minor code issues in tidal 2019-06-18 23:39:16 +02:00
Jonas Kvinge
dabd6f8284 Fix Subsonic API path 2019-06-18 23:25:10 +02:00
Jonas Kvinge
beb3ab463f Add missing subsonic fts songs table 2019-06-18 14:41:48 +02:00
Jonas Kvinge
1d67b623e0 Use single url setting instead for subsonic, check http code 2019-06-18 01:22:03 +02:00
Jonas Kvinge
2c8cde4d91 Add scheme setting for subsonic 2019-06-18 00:28:36 +02:00
Jonas Kvinge
8cc1d48115 Fix max concurrent requests in tidal 2019-06-18 00:02:43 +02:00
Jonas Kvinge
ec2468fb8d Remove unneeded include 2019-06-18 00:02:22 +02:00
Jonas Kvinge
7b54cef23b Add Subsonic support (#180) 2019-06-17 23:54:24 +02:00
Jonas Kvinge
a9da8811fc Turn off ssl-strict in gst pipeline 2019-06-17 23:01:38 +02:00
Jonas Kvinge
60e86b9881 Fix fading options 2019-06-17 02:23:51 +02:00
Jonas Kvinge
a6766f3c99 Fix gapless playback when using url handler 2019-06-15 19:32:26 +02:00
Jonas Kvinge
e59c3c6f70 Add MediaUrl function for playlistitems 2019-06-15 19:31:43 +02:00
Jonas Kvinge
49aa344d8b Change index to idx 2019-06-15 19:31:16 +02:00
Jonas Kvinge
4fed6ab298 Hide tidal oauth settings until streaming is possible 2019-06-14 23:02:57 +02:00
Jonas Kvinge
58eab4d3bc Fix verifying xml in tidal stream url 2019-06-14 23:02:33 +02:00
Jonas Kvinge
5ef5da687d Fix macOS build 2019-06-12 06:34:59 +02:00
Jonas Kvinge
4875d319dc Add love button 2019-06-12 00:38:52 +02:00
Jonas Kvinge
fb5a53435e Remove unused function 2019-06-11 19:28:48 +02:00
Jonas Kvinge
4f805d65b3 Fix need_login function 2019-06-11 19:26:00 +02:00
Jonas Kvinge
56ffb0deb1 Fix code challenge in tidal oauth 2019-06-10 02:29:57 +02:00
Jonas Kvinge
c0c1457073 Add optional oauth authentication for tidal 2019-06-09 19:29:25 +02:00
Jonas Kvinge
85a0748ad9 Add x-scheme-handler/tidal to desktop file 2019-06-09 03:10:37 +02:00
Jonas Kvinge
c1939a36dd Change CMakeLists.txt to use list APPEND for Qt5 2019-06-08 22:03:10 +02:00
Jonas Kvinge
b7c394b7a5 Disable fading when volume control is disabled 2019-06-08 12:04:04 +02:00
Jonas Kvinge
a070681f89 Move to private 2019-06-08 12:03:48 +02:00
Jonas Kvinge
d5e424eec8 Fix save/restore group by for internet collection 2019-06-08 00:15:54 +02:00
Jonas Kvinge
e0366d38f1 Change remove from favorites icon 2019-06-08 00:14:11 +02:00
Jonas Kvinge
cbf1d96b16 Avoid duplicate songs in the collection backend 2019-06-07 23:02:43 +02:00
Jonas Kvinge
7cc0d6bb5a Fix ItemFromSong() missing album id 2019-06-07 22:54:34 +02:00
Jonas Kvinge
e19b840ee6 Tidal artist id fixes 2019-06-07 21:02:28 +02:00
Jonas Kvinge
5c2ca1e3d9 Add tidal add/remove favorites + more tidal fixes 2019-06-07 20:23:05 +02:00
Jonas Kvinge
059c4beb30 Improve lyrics searcher 2019-06-06 18:22:41 +02:00
Jonas Kvinge
427808226f Change snap interface to network-manager-observe 2019-06-01 14:29:00 +02:00
Jonas Kvinge
5448245942 Update libprotobuf 2019-05-31 20:47:36 +02:00
Jonas Kvinge
34ab907007 Remove unused code 2019-05-31 20:47:15 +02:00
Jonas Kvinge
e5fde27859 Fix crash in tidal service 2019-05-31 02:32:01 +02:00
Jonas Kvinge
699e8e3ddb Fix schemas 2019-05-31 01:41:17 +02:00
Jonas Kvinge
28ee967371 Fix compile without xinescope 2019-05-31 01:29:56 +02:00
Jonas Kvinge
1b0b5f2554 Remove assert 2019-05-30 19:11:46 +02:00
Jonas Kvinge
1bcc86f989 Fix song search fetchalbums option 2019-05-30 18:46:17 +02:00
Jonas Kvinge
f26f932fd7 Queue tidal requests 2019-05-30 18:06:48 +02:00
Jonas Kvinge
2b7d48ce77 Distinguish albums with same name with album_id 2019-05-30 18:05:07 +02:00
Jonas Kvinge
111712fd6d Add artist_id, album_id and song id to songs 2019-05-30 18:04:30 +02:00
Jonas Kvinge
7609bc181e Implement offset to all Tidal requests 2019-05-29 17:39:51 +02:00
Jonas Kvinge
8b05af7ca3 Make xine analyzer optional 2019-05-28 18:37:51 +02:00
Jonas Kvinge
20f9108ebf Fix artists and albums limit 2019-05-28 17:34:44 +02:00
Jonas Kvinge
cecae7cdc3 Fix xine metronom compile 2019-05-27 21:56:07 +02:00
Jonas Kvinge
e5f3123567 Fix gst_pad_send_event block in ErrorMessageReceived() 2019-05-27 21:39:38 +02:00
Jonas Kvinge
27b0e27cfd initialize search id in the constructor. 2019-05-27 21:38:39 +02:00
Jonas Kvinge
890fba0f61 Add internet tabs view and tidal favorites (#167) 2019-05-27 21:10:37 +02:00
Jonas Kvinge
c4b732ff93 Add proper error handling to local redirectserver 2019-05-21 22:51:53 +02:00
Jonas Kvinge
b8fa2985d5 Fix Tidal SendLogin signal 2019-05-20 19:14:33 +02:00
Jonas Kvinge
ba741fbce8 Exclude version and path from singleapplication, dont start if message
could not be sent.
2019-05-20 18:41:12 +02:00
Jonas Kvinge
67d070c334 Increase default timeout 2019-05-20 18:40:34 +02:00
Jonas Kvinge
8576afe6f5 Fix return value of sendMessage() 2019-05-20 18:39:49 +02:00
Jonas Kvinge
36807fd376 Validate track duration 2019-05-14 19:07:02 +02:00
Jonas Kvinge
2ad1d27a59 Remove stream schema setting and add Add HI_RES option 2019-05-14 18:45:38 +02:00
Jonas Kvinge
7cc9c75d15 Make tidal token configurable 2019-05-13 23:49:09 +02:00
Jonas Kvinge
f33609bbf8 Compare artist and album case-insensitive 2019-05-13 22:38:24 +02:00
Jonas Kvinge
69eeb4b0f8 Move QSearchField to widgets and remove rest of qocoa 2019-05-08 23:34:44 +02:00
Jonas Kvinge
aa583ec1aa Set ContentTypeHeader for Tidal requests 2019-05-08 23:08:29 +02:00
Jonas Kvinge
2b9f153257 Add missing stage packages to snap 2019-05-07 21:04:52 +02:00
Jonas Kvinge
cb9b7fc917 Update appdata desktop file 2019-05-07 17:03:20 +02:00
Jonas Kvinge
74b36c8884 Remove some unneeded interfaces from the snap 2019-05-07 17:02:58 +02:00
Jonas Kvinge
89ff7d6dae Change api url of tidal cover provider 2019-05-06 18:18:31 +02:00
Jonas Kvinge
91df420cb4 Update Dockerfile 2019-05-05 23:51:59 +02:00
Jonas Kvinge
fc25c9f0bc Turn on git revision 2019-05-05 23:51:46 +02:00
Jonas Kvinge
12a27e3a8d Update snap version 2019-05-05 23:28:41 +02:00
Jonas Kvinge
125e32ff00 Release 0.5.5 2019-05-05 21:27:31 +02:00
Jonas Kvinge
4a110633e8 Use customized docker image for travis-ci 2019-05-05 21:20:39 +02:00
Jonas Kvinge
65648f8abd Change Tidal API url 2019-05-05 21:20:28 +02:00
Jonas Kvinge
50174861dc Turn back git revision 2019-05-05 21:20:05 +02:00
702 changed files with 35496 additions and 19680 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
github: jonaski

27
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots:**
If applicable, add screenshots to help explain your problem.
**System Information:**
- Operating system:
- Strawberry Version:
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View File

@@ -7,48 +7,51 @@ services:
- docker
compiler:
- gcc
- clang
before_install:
- echo $DEPLOY_KEY_ENC | base64 --decode | openssl aes-256-cbc -K $encrypted_83a41ac424a6_key -iv $encrypted_83a41ac424a6_iv -out ~/.ssh/id_rsa -d
- chmod 600 ~/.ssh/id_rsa
- if ! [ "$DEPLOY_KEY_ENC" == "" ]; then
echo $DEPLOY_KEY_ENC | base64 --decode | openssl aes-256-cbc -K $encrypted_83a41ac424a6_key -iv $encrypted_83a41ac424a6_iv -out ~/.ssh/id_rsa -d ;
chmod 600 ~/.ssh/id_rsa ;
fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
docker build -f Dockerfile -t strawberry-build .;
docker run --name build -itd strawberry-build /bin/bash;
docker build -f Dockerfile -t strawberry-build . || travis_terminate 1;
docker run --name build -itd strawberry-build /bin/bash || travis_terminate 1;
docker exec build git clone https://github.com/jonaski/strawberry;
fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
git fetch --unshallow;
git pull;
brew update;
brew unlink python;
brew install glib pkgconfig libffi protobuf protobuf-c qt gettext gnutls fftw;
brew install sqlite --with-fts;
brew install gstreamer gst-plugins-base;
brew install gst-plugins-good --with-flac;
brew install gst-plugins-bad gst-plugins-ugly gst-libav;
brew install chromaprint;
git fetch --unshallow || travis_terminate 1;
git pull || travis_terminate 1;
brew update || travis_terminate 1;
brew unlink python || travis_terminate 1;
brew install glib pkgconfig libffi protobuf protobuf-c qt gettext gnutls fftw sqlite chromaprint;
brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav;
brew install libcdio libmtp libimobiledevice libplist;
brew install create-dmg;
export Qt5_DIR=/usr/local/opt/qt5/lib/cmake;
export Qt5LinguistTools_DIR=/usr/local/Cellar/qt/$(ls /usr/local/Cellar/qt | head -n1)/lib/cmake/Qt5LinguistTools;
export Qt5LinguistTools_DIR=/usr/local/opt/qt5/lib/cmake/Qt5LinguistTools;
export PATH="/usr/local/opt/gettext/bin:$PATH";
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/$(ls /usr/local/Cellar/libffi | head -n1)/lib/pkgconfig/:$PKG_CONFIG_PATH;
export PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig/:$PKG_CONFIG_PATH;
ls /usr/local/lib/gstreamer-1.0;
fi
before_script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec build cmake -Hstrawberry -Bbuild -DENABLE_TRANSLATIONS=ON ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir build; cd build; cmake .. -DUSE_BUNDLE=ON -DENABLE_TRANSLATIONS=ON ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec build cmake -Hstrawberry -Bbuild ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir build; cd build; cmake .. -DUSE_BUNDLE=ON ; fi
script:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker exec build make -C build -j8 ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
make -j8;
sudo make install;
sudo ../dist/macos/macdeploy.py strawberry.app;
../dist/macos/create-dmg.sh strawberry.app $CC_FOR_BUILD;
make -j8 || travis_terminate 1;
make install || travis_terminate 1;
sudo make dmg;
fi
after_success:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls -lh strawberry.dmg; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$TRAVIS_BRANCH" == "master" ]]; then rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ls -lh strawberry*.dmg; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$CC_FOR_BUILD" == "gcc" ]] && [ -f ~/.ssh/id_rsa ]; then
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos;
elif [[ "$TRAVIS_BRANCH" == "macos" ]]; then
rsync -e "ssh -o StrictHostKeyChecking=no" -va strawberry*.dmg travis@echoes.jkvinge.net:/home/travis/builds/macos-test;
fi
fi
branches:
except:

19
3rdparty/README.md vendored
View File

@@ -19,7 +19,7 @@ TagLib is a library for reading and editing the meta-data of several popular aud
by Strawberry to identify audio files. It is important that it is kept up-to-date for Strawberry to function
correctly.
It is kept in 3rdparty because there currently is no offical release of TagLib with the features and bugfixes
It is kept in 3rdparty because there currently is no official release of TagLib with the features and bugfixes
that are in the official repository. And also because some distros use older, or unpatched versions.
There is a bug in the latest version (1.11.1) corrupting Ogg files,
@@ -37,21 +37,6 @@ URL: https://github.com/taglib/taglib
utf8-cpp
--------
This is 2 header files used by taglib, but kept in a seperate directory because it is maintained by others.
This is 2 header files used by taglib, but kept in a separate directory because it is maintained by others.
URL: http://utfcpp.sourceforge.net/
qocoa
-----
This is a small static library currently used for the search fields above the collection, playlist and in
the cover manager. It is slightly modified from original version.
URL: https://github.com/mikemcquaid/Qocoa
SPMediaKeyTap
-------------
This is used for macOS only to enable strawberry to grab global shortcuts and can safely be deleted on other
platforms.

View File

@@ -1,13 +0,0 @@
set(SPMEDIAKEY-SOURCES
SPMediaKeyTap.m
SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m
)
set(SPMEDIAKEY-HEADERS
SPMediaKeyTap.h
SPInvocationGrabbing/NSObject+SPInvocationGrabbing.h
)
ADD_LIBRARY(SPMediaKeyTap STATIC
${SPMEDIAKEY-SOURCES}
)

View File

@@ -1,8 +0,0 @@
Copyright (c) 2011, Joachim Bengtsson
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,12 +0,0 @@
SPMediaKeyTap
=============
`SPMediaKeyTap` abstracts a `CGEventHook` and other nastiness in order to give you a relatively simple API to receive media key events (prev/next/playpause, on F7 to F9 on modern MacBook Pros) exclusively, without them reaching other applications like iTunes. `SPMediaKeyTap` is clever enough to resign its exclusive lock on media keys by looking for which application was active most recently: if that application is in `SPMediaKeyTap`'s whitelist, it will resign the keys. This is similar to the behavior of Apple's applications collaborating on media key handling exclusivity, but unfortunately, Apple are not exposing any APIs allowing third-parties to join in on this collaboration.
For now, the whitelist is just a hardcoded array in `+[SPMediaKeyTap defaultMediaKeyUserBundleIdentifiers]`. If your app starts using `SPMediaKeyTap`, please [mail me](mailto:nevyn@spotify.com) your bundle ID, and I'll include it in the canonical repository. This is a bad solution; a better solution would be to use distributed notifications to collaborate in creating this whitelist at runtime. Hopefully someone'll have the time and energy to write this soon.
In `Example/SPMediaKeyTapExampleAppDelegate.m` is an example of both how you use `SPMediaKeyTap`, and how you handle the semi-private `NSEvent` subtypes involved in media keys, including on how to fall back to non-event tap handling of these events.
`SPMediaKeyTap` and other `CGEventHook`s on the event type `NSSystemDefined` is known to interfere with each other and applications doing weird stuff with mouse input, because mouse clicks are also part of the `NSSystemDefined` category. The single issue we have had reported here at Spotify is Adobe Fireworks, in which item selection stops working with `SPMediaKeyTap` is active.
`SPMediaKeyTap` requires 10.5 to work, and disables itself on 10.4.

View File

@@ -1,30 +0,0 @@
#import <Foundation/Foundation.h>
@interface SPInvocationGrabber : NSObject {
id _object;
NSInvocation *_invocation;
int frameCount;
char **frameStrings;
BOOL backgroundAfterForward;
BOOL onMainAfterForward;
BOOL waitUntilDone;
}
-(id)initWithObject:(id)obj;
-(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
@property (readonly, retain, nonatomic) id object;
@property (readonly, retain, nonatomic) NSInvocation *invocation;
@property BOOL backgroundAfterForward;
@property BOOL onMainAfterForward;
@property BOOL waitUntilDone;
-(void)invoke; // will release object and invocation
-(void)printBacktrace;
-(void)saveBacktrace;
@end
@interface NSObject (SPInvocationGrabbing)
-(id)grab;
-(id)invokeAfter:(NSTimeInterval)delta;
-(id)nextRunloop;
-(id)inBackground;
-(id)onMainAsync:(BOOL)async;
@end

View File

@@ -1,128 +0,0 @@
#import "NSObject+SPInvocationGrabbing.h"
#import <execinfo.h>
#pragma mark Invocation grabbing
@interface SPInvocationGrabber ()
@property (readwrite, retain, nonatomic) id object;
@property (readwrite, retain, nonatomic) NSInvocation *invocation;
@end
@implementation SPInvocationGrabber
- (id)initWithObject:(id)obj;
{
return [self initWithObject:obj stacktraceSaving:YES];
}
-(id)initWithObject:(id)obj stacktraceSaving:(BOOL)saveStack;
{
self.object = obj;
if(saveStack)
[self saveBacktrace];
return self;
}
-(void)dealloc;
{
free(frameStrings);
self.object = nil;
self.invocation = nil;
[super dealloc];
}
@synthesize invocation = _invocation, object = _object;
@synthesize backgroundAfterForward, onMainAfterForward, waitUntilDone;
- (void)runInBackground;
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
@try {
[self invoke];
}
@finally {
[pool drain];
}
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
[anInvocation retainArguments];
anInvocation.target = _object;
self.invocation = anInvocation;
if(backgroundAfterForward)
[NSThread detachNewThreadSelector:@selector(runInBackground) toTarget:self withObject:nil];
else if(onMainAfterForward)
[self performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:waitUntilDone];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)inSelector {
NSMethodSignature *signature = [super methodSignatureForSelector:inSelector];
if (signature == NULL)
signature = [_object methodSignatureForSelector:inSelector];
return signature;
}
- (void)invoke;
{
@try {
[_invocation invoke];
}
@catch (NSException * e) {
NSLog(@"SPInvocationGrabber's target raised %@:\n\t%@\nInvocation was originally scheduled at:", e.name, e);
[self printBacktrace];
printf("\n");
[e raise];
}
self.invocation = nil;
self.object = nil;
}
-(void)saveBacktrace;
{
void *backtraceFrames[128];
frameCount = backtrace(&backtraceFrames[0], 128);
frameStrings = backtrace_symbols(&backtraceFrames[0], frameCount);
}
-(void)printBacktrace;
{
int x;
for(x = 3; x < frameCount; x++) {
if(frameStrings[x] == NULL) { break; }
printf("%s\n", frameStrings[x]);
}
}
@end
@implementation NSObject (SPInvocationGrabbing)
-(id)grab;
{
return [[[SPInvocationGrabber alloc] initWithObject:self] autorelease];
}
-(id)invokeAfter:(NSTimeInterval)delta;
{
id grabber = [self grab];
[NSTimer scheduledTimerWithTimeInterval:delta target:grabber selector:@selector(invoke) userInfo:nil repeats:NO];
return grabber;
}
- (id)nextRunloop;
{
return [self invokeAfter:0];
}
-(id)inBackground;
{
SPInvocationGrabber *grabber = [self grab];
grabber.backgroundAfterForward = YES;
return grabber;
}
-(id)onMainAsync:(BOOL)async;
{
SPInvocationGrabber *grabber = [self grab];
grabber.onMainAfterForward = YES;
grabber.waitUntilDone = !async;
return grabber;
}
@end

View File

@@ -1,28 +0,0 @@
// A
+(UIView*)flashAt:(CGRect)r in:(UIView*)parent color:(UIColor*)color;
{
float duration = 0.5;
UIView *flash = [[[UIView alloc] initWithFrame:r] autorelease];
flash.backgroundColor = color;
[parent addSubview:flash];
[[flash invokeAfter:duration+0.1] removeFromSuperview];
[UIView beginAnimations:@"SPFlash" context:NULL];
[UIView setAnimationDuration:duration];
flash.alpha = 0.0;
[UIView commitAnimations];
return flash;
}
// B
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Force the animation to happen by calling this method again after a small
// delay - see http://blog.instapaper.com/post/53568356
[[self nextRunloop] delayedTableViewDidSelectRowAtIndexPath: indexPath];
}
// C
[[tableView invokeAfter:0.15] selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
[[tableView invokeAfter:0.30] deselectRowAtIndexPath:indexPath animated:YES];
[[tableView invokeAfter:0.45] selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];

View File

@@ -1,12 +0,0 @@
@interface MyClass : NSObject
-(BOOL)areTheNewViewersGoneYet:(Duck*)duck;
@end
...
MyClass *myInstance = [[MyClass alloc] init];
id invocationGrabber = [[[SPInvocationGrabber alloc] initWithTarget:myInstance] autorelease];
[invocationGrabber areTheNewViewersGoneYet:[Duck yellowDuck]]; // line 9
NSInvocation *invocationForAreTheNewViewersGoneYet = [invocationGrabber invocation];

View File

@@ -1,38 +0,0 @@
#import <Cocoa/Cocoa.h>
#import "NSObject+SPInvocationGrabbing.h"
@interface Foo : NSObject {
int a;
}
-(void)startIt;
-(void)theBackgroundStuff;
-(void)theForegroundStuff;
@end
@implementation Foo
-(void)startIt;
{
NSLog(@"Starting out on the main thread...");
a = 3;
[[self inBackground] theBackgroundStuff];
}
-(void)theBackgroundStuff;
{
NSLog(@"Woah, this is a background thread!");
a += 6;
[[self onMainAsync:YES] theForegroundStuff];
}
-(void)theForegroundStuff;
{
NSLog(@"Hey presto: %d", a);
}
@end
int main() {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
Foo *foo = [Foo new];
[foo startIt];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
[pool release];
return 0;
}

View File

@@ -1,34 +0,0 @@
#include <Cocoa/Cocoa.h>
#import <IOKit/hidsystem/ev_keymap.h>
#import <Carbon/Carbon.h>
// http://overooped.com/post/2593597587/mediakeys
#define SPSystemDefinedEventMediaKeys 8
@interface SPMediaKeyTap : NSObject {
EventHandlerRef _app_switching_ref;
EventHandlerRef _app_terminating_ref;
CFMachPortRef _eventPort;
CFRunLoopSourceRef _eventPortSource;
CFRunLoopRef _tapThreadRL;
BOOL _shouldInterceptMediaKeyEvents;
id _delegate;
// The app that is frontmost in this list owns media keys
NSMutableArray *_mediaKeyAppList;
}
+ (NSArray*)defaultMediaKeyUserBundleIdentifiers;
-(id)initWithDelegate:(id)delegate;
+(BOOL)usesGlobalMediaKeyTap;
-(void)startWatchingMediaKeys;
-(void)stopWatchingMediaKeys;
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event;
@end
@interface NSObject (SPMediaKeyTapDelegate)
-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
@end
extern NSString *kMediaKeyUsingBundleIdentifiersDefaultsKey;

View File

@@ -1,300 +0,0 @@
// Copyright (c) 2010 Spotify AB
#import "SPMediaKeyTap.h"
#import "SPInvocationGrabbing/NSObject+SPInvocationGrabbing.h" // https://gist.github.com/511181, in submodule
@interface SPMediaKeyTap ()
-(BOOL)shouldInterceptMediaKeyEvents;
-(void)setShouldInterceptMediaKeyEvents:(BOOL)newSetting;
-(void)startWatchingAppSwitching;
-(void)stopWatchingAppSwitching;
-(void)eventTapThread;
@end
static SPMediaKeyTap *singleton = nil;
static pascal OSStatus appSwitched (EventHandlerCallRef nextHandler, EventRef evt, void* userData);
static pascal OSStatus appTerminated (EventHandlerCallRef nextHandler, EventRef evt, void* userData);
static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon);
// Inspired by http://gist.github.com/546311
@implementation SPMediaKeyTap
#pragma mark -
#pragma mark Setup and teardown
-(id)initWithDelegate:(id)delegate;
{
_delegate = delegate;
[self startWatchingAppSwitching];
singleton = self;
_mediaKeyAppList = [NSMutableArray new];
return self;
}
-(void)dealloc;
{
[self stopWatchingMediaKeys];
[self stopWatchingAppSwitching];
[_mediaKeyAppList release];
[super dealloc];
}
-(void)startWatchingAppSwitching;
{
// Listen to "app switched" event, so that we don't intercept media keys if we
// weren't the last "media key listening" app to be active
EventTypeSpec eventType = { kEventClassApplication, kEventAppFrontSwitched };
OSStatus err = InstallApplicationEventHandler(NewEventHandlerUPP(appSwitched), 1, &eventType, self, &_app_switching_ref);
assert(err == noErr);
eventType.eventKind = kEventAppTerminated;
err = InstallApplicationEventHandler(NewEventHandlerUPP(appTerminated), 1, &eventType, self, &_app_terminating_ref);
assert(err == noErr);
}
-(void)stopWatchingAppSwitching;
{
if(!_app_switching_ref) return;
RemoveEventHandler(_app_switching_ref);
_app_switching_ref = NULL;
}
-(void)startWatchingMediaKeys;{
[self setShouldInterceptMediaKeyEvents:YES];
// Add an event tap to intercept the system defined media key events
_eventPort = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap,
kCGEventTapOptionDefault,
CGEventMaskBit(NX_SYSDEFINED),
tapEventCallback,
self);
assert(_eventPort != NULL);
_eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorSystemDefault, _eventPort, 0);
assert(_eventPortSource != NULL);
// Let's do this in a separate thread so that a slow app doesn't lag the event tap
[NSThread detachNewThreadSelector:@selector(eventTapThread) toTarget:self withObject:nil];
}
-(void)stopWatchingMediaKeys;
{
// TODO<nevyn>: Shut down thread, remove event tap port and source
}
#pragma mark -
#pragma mark Accessors
+(BOOL)usesGlobalMediaKeyTap
{
#ifdef _DEBUG
// breaking in gdb with a key tap inserted sometimes locks up all mouse and keyboard input forever, forcing reboot
return NO;
#else
// XXX(nevyn): MediaKey event tap doesn't work on 10.4, feel free to figure out why if you have the energy.
return floor(NSAppKitVersionNumber) >= 949/*NSAppKitVersionNumber10_5*/;
#endif
}
+ (NSArray*)defaultMediaKeyUserBundleIdentifiers;
{
return [NSArray arrayWithObjects:
[[NSBundle mainBundle] bundleIdentifier], // your app
@"com.spotify.client",
@"com.apple.iTunes",
@"com.apple.QuickTimePlayerX",
@"com.apple.quicktimeplayer",
@"com.apple.iWork.Keynote",
@"com.apple.iPhoto",
@"org.videolan.vlc",
@"com.apple.Aperture",
@"com.plexsquared.Plex",
@"com.soundcloud.desktop",
@"com.macromedia.fireworks", // the tap messes up their mouse input
nil
];
}
-(BOOL)shouldInterceptMediaKeyEvents;
{
BOOL shouldIntercept = NO;
@synchronized(self) {
shouldIntercept = _shouldInterceptMediaKeyEvents;
}
return shouldIntercept;
}
-(void)pauseTapOnTapThread:(BOOL)yeahno;
{
CGEventTapEnable(self->_eventPort, yeahno);
}
-(void)setShouldInterceptMediaKeyEvents:(BOOL)newSetting;
{
BOOL oldSetting;
@synchronized(self) {
oldSetting = _shouldInterceptMediaKeyEvents;
_shouldInterceptMediaKeyEvents = newSetting;
}
if(_tapThreadRL && oldSetting != newSetting) {
id grab = [self grab];
[grab pauseTapOnTapThread:newSetting];
NSTimer *timer = [NSTimer timerWithTimeInterval:0 invocation:[grab invocation] repeats:NO];
CFRunLoopAddTimer(_tapThreadRL, (CFRunLoopTimerRef)timer, kCFRunLoopCommonModes);
}
}
#pragma mark
#pragma mark -
#pragma mark Event tap callbacks
// Note: method called on background thread
static CGEventRef tapEventCallback2(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
SPMediaKeyTap *self = refcon;
if(type == kCGEventTapDisabledByTimeout) {
NSLog(@"Media key event tap was disabled by timeout");
CGEventTapEnable(self->_eventPort, TRUE);
return event;
} else if(type == kCGEventTapDisabledByUserInput) {
// Was disabled manually by -[pauseTapOnTapThread]
return event;
}
NSEvent *nsEvent = nil;
@try {
nsEvent = [NSEvent eventWithCGEvent:event];
}
@catch (NSException * e) {
NSLog(@"Strange CGEventType: %d: %@", type, e);
assert(0);
return event;
}
if (type != NX_SYSDEFINED || [nsEvent subtype] != SPSystemDefinedEventMediaKeys)
return event;
int keyCode = (([nsEvent data1] & 0xFFFF0000) >> 16);
if (keyCode != NX_KEYTYPE_PLAY && keyCode != NX_KEYTYPE_FAST && keyCode != NX_KEYTYPE_REWIND)
return event;
if (![self shouldInterceptMediaKeyEvents])
return event;
[nsEvent retain]; // matched in handleAndReleaseMediaKeyEvent:
[self performSelectorOnMainThread:@selector(handleAndReleaseMediaKeyEvent:) withObject:nsEvent waitUntilDone:NO];
return NULL;
}
static CGEventRef tapEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
CGEventRef ret = tapEventCallback2(proxy, type, event, refcon);
[pool drain];
return ret;
}
// event will have been retained in the other thread
-(void)handleAndReleaseMediaKeyEvent:(NSEvent *)event {
[event autorelease];
[_delegate mediaKeyTap:self receivedMediaKeyEvent:event];
}
-(void)eventTapThread;
{
_tapThreadRL = CFRunLoopGetCurrent();
CFRunLoopAddSource(_tapThreadRL, _eventPortSource, kCFRunLoopCommonModes);
CFRunLoopRun();
}
#pragma mark Task switching callbacks
NSString *kMediaKeyUsingBundleIdentifiersDefaultsKey = @"SPApplicationsNeedingMediaKeys";
-(void)mediaKeyAppListChanged;
{
if([_mediaKeyAppList count] == 0) return;
/*NSLog(@"--");
int i = 0;
for (NSValue *psnv in _mediaKeyAppList) {
ProcessSerialNumber psn; [psnv getValue:&psn];
NSDictionary *processInfo = [(id)ProcessInformationCopyDictionary(
&psn,
kProcessDictionaryIncludeAllInformationMask
) autorelease];
NSString *bundleIdentifier = [processInfo objectForKey:(id)kCFBundleIdentifierKey];
NSLog(@"%d: %@", i++, bundleIdentifier);
}*/
ProcessSerialNumber mySerial, topSerial;
GetCurrentProcess(&mySerial);
[[_mediaKeyAppList objectAtIndex:0] getValue:&topSerial];
Boolean same;
OSErr err = SameProcess(&mySerial, &topSerial, &same);
[self setShouldInterceptMediaKeyEvents:(err == noErr && same)];
}
-(void)appIsNowFrontmost:(ProcessSerialNumber)psn;
{
NSValue *psnv = [NSValue valueWithBytes:&psn objCType:@encode(ProcessSerialNumber)];
NSDictionary *processInfo = [(id)ProcessInformationCopyDictionary(
&psn,
kProcessDictionaryIncludeAllInformationMask
) autorelease];
NSString *bundleIdentifier = [processInfo objectForKey:(id)kCFBundleIdentifierKey];
NSArray *whitelistIdentifiers = [[NSUserDefaults standardUserDefaults] arrayForKey:kMediaKeyUsingBundleIdentifiersDefaultsKey];
if(![whitelistIdentifiers containsObject:bundleIdentifier]) return;
[_mediaKeyAppList removeObject:psnv];
[_mediaKeyAppList insertObject:psnv atIndex:0];
[self mediaKeyAppListChanged];
}
-(void)appTerminated:(ProcessSerialNumber)psn;
{
NSValue *psnv = [NSValue valueWithBytes:&psn objCType:@encode(ProcessSerialNumber)];
[_mediaKeyAppList removeObject:psnv];
[self mediaKeyAppListChanged];
}
static pascal OSStatus appSwitched (EventHandlerCallRef nextHandler, EventRef evt, void* userData)
{
SPMediaKeyTap *self = (id)userData;
ProcessSerialNumber newSerial;
GetFrontProcess(&newSerial);
[self appIsNowFrontmost:newSerial];
return CallNextEventHandler(nextHandler, evt);
}
static pascal OSStatus appTerminated (EventHandlerCallRef nextHandler, EventRef evt, void* userData)
{
SPMediaKeyTap *self = (id)userData;
ProcessSerialNumber deadPSN;
GetEventParameter(
evt,
kEventParamProcessID,
typeProcessSerialNumber,
NULL,
sizeof(deadPSN),
NULL,
&deadPSN
);
[self appTerminated:deadPSN];
return CallNextEventHandler(nextHandler, evt);
}
@end

View File

@@ -1,25 +0,0 @@
-(void)mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
{
assert([event type] == NSSystemDefined && [event subtype] == SPSystemDefinedEventMediaKeys);
int keyCode = (([event data1] & 0xFFFF0000) >> 16);
int keyFlags = ([event data1] & 0x0000FFFF);
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
int keyRepeat = (keyFlags & 0x1);
if (keyState == 1 && windowController != NULL) {
switch (keyCode) {
case NX_KEYTYPE_PLAY:
... return;
case NX_KEYTYPE_FAST:
... return;
case NX_KEYTYPE_REWIND:
... return;
}
}
}

View File

@@ -1,38 +0,0 @@
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__")
set(SOURCES)
set(HEADERS
qsearchfield.h
qbutton.h
qprogressindicatorspinning.h
)
qt5_wrap_cpp(MOC_SOURCES ${HEADERS})
if(APPLE)
list(APPEND SOURCES
qsearchfield_mac.mm
qbutton_mac.mm
qprogressindicatorspinning_mac.mm
)
else()
list(APPEND SOURCES
qsearchfield_nonmac.cpp
qbutton_nonmac.cpp
qprogressindicatorspinning_nonmac.cpp
)
set(RESOURCES
qsearchfield_nonmac.qrc
qprogressindicatorspinning_nonmac.qrc
)
qt5_add_resources(RESOURCES_SOURCES ${RESOURCES})
endif()
add_library(Qocoa STATIC ${SOURCES} ${MOC_SOURCES} ${RESOURCES_SOURCES})
target_link_libraries(Qocoa ${QT_LIBRARIES})

View File

@@ -1,19 +0,0 @@
Copyright (C) 2011 by Mike McQuaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,38 +0,0 @@
# Qocoa
Qocoa is a collection of Qt wrappers for OSX's Cocoa widgets.
## Features
- basic fallback to sensible Qt types on non-OSX platforms
- shared class headers which expose no implementation details
- typical Qt signal/slot-based API
- trivial to import into projects (class header/implementation, [single shared global header](https://github.com/mikemcquaid/Qocoa/blob/master/qocoa_mac.h))
## Building
```
git clone git://github.com/mikemcquaid/Qocoa.git
cd Qocoa
qmake # or cmake .
make
```
## Status
I'm not personally working on this any more but will accept pull-requests.
[![Build Status](https://travis-ci.org/MikeMcQuaid/Qocoa.svg?branch=master)](https://travis-ci.org/MikeMcQuaid/Qocoa)
## Usage
For each class you want to use copy the [`qocoa_mac.h`](https://github.com/mikemcquaid/Qocoa/blob/master/qocoa_mac.h), `$CLASS.h`, `$CLASS_mac.*` and `$CLASS_nonmac.*` files into your source tree and add them to your buildsystem. Examples are provided for [CMake](https://github.com/mikemcquaid/Qocoa/blob/master/CMakeLists.txt) and [QMake](https://github.com/mikemcquaid/Qocoa/blob/master/Qocoa.pro).
## Contact
[Mike McQuaid](mailto:mike@mikemcquaid.com)
## License
Qocoa is licensed under the [MIT License](http://en.wikipedia.org/wiki/MIT_License).
The full license text is available in [LICENSE.txt](https://github.com/mikemcquaid/Qocoa/blob/master/LICENSE.txt).
Magnifier and EditClear icons taken from [QtCreator](http://qt-project.org/) and are licensed under the [LGPL](http://www.gnu.org/copyleft/lesser.html).
Other icons are taken from the [Oxygen Project](http://www.oxygen-icons.org/) and are licensed under the [Creative Commons Attribution-ShareAlike 3.0 License](http://creativecommons.org/licenses/by-sa/3.0/).
## Gallery
![Qocoa Gallery](https://github.com/mikemcquaid/Qocoa/raw/master/gallery.png)

View File

@@ -1,13 +0,0 @@
Widgets I hope to implement (or at least investigate):
- NSTokenField
- NSSegmentedControl
- NSLevelIndicator
- NSPathControl
- NSSlider (Circular)
- NSSplitView
- NSTextFinder
- NSOutlineView in an NSScrollView (Source List)
- NSDrawer
- PDFView
- WebView

View File

@@ -1,49 +0,0 @@
#ifndef QBUTTON_H
#define QBUTTON_H
#include <QWidget>
#include <QPointer>
class QButtonPrivate;
class QButton : public QWidget
{
Q_OBJECT
public:
// Matches NSBezelStyle
enum BezelStyle {
Rounded = 1,
RegularSquare = 2,
Disclosure = 5,
ShadowlessSquare = 6,
Circular = 7,
TexturedSquare = 8,
HelpButton = 9,
SmallSquare = 10,
TexturedRounded = 11,
RoundRect = 12,
Recessed = 13,
RoundedDisclosure = 14,
#ifdef __MAC_10_7
Inline = 15
#endif
};
explicit QButton(QWidget *parent, BezelStyle bezelStyle = Rounded);
public slots:
void setText(const QString &text);
void setImage(const QPixmap &image);
void setChecked(bool checked);
public:
void setCheckable(bool checkable);
bool isChecked();
signals:
void clicked(bool checked = false);
private:
friend class QButtonPrivate;
QPointer<QButtonPrivate> pimpl;
};
#endif // QBUTTON_H

View File

@@ -1,229 +0,0 @@
/*
Copyright (C) 2011 by Mike McQuaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "qbutton.h"
#include "qocoa_mac.h"
#import "Foundation/NSAutoreleasePool.h"
#import "AppKit/NSButton.h"
#import "AppKit/NSFont.h"
class QButtonPrivate : public QObject
{
public:
QButtonPrivate(QButton *qButton, NSButton *nsButton, QButton::BezelStyle bezelStyle)
: QObject(qButton), qButton(qButton), nsButton(nsButton)
{
switch(bezelStyle) {
case QButton::Disclosure:
case QButton::Circular:
#ifdef __MAC_10_7
case QButton::Inline:
#endif
case QButton::RoundedDisclosure:
case QButton::HelpButton:
[nsButton setTitle:@""];
default:
break;
}
NSFont* font = 0;
switch(bezelStyle) {
case QButton::RoundRect:
font = [NSFont fontWithName:@"Lucida Grande" size:12];
break;
case QButton::Recessed:
font = [NSFont fontWithName:@"Lucida Grande Bold" size:12];
break;
#ifdef __MAC_10_7
case QButton::Inline:
font = [NSFont boldSystemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
break;
#endif
default:
font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
break;
}
[nsButton setFont:font];
switch(bezelStyle) {
case QButton::Rounded:
qButton->setMinimumWidth(40);
qButton->setFixedHeight(24);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
break;
case QButton::RegularSquare:
case QButton::TexturedSquare:
qButton->setMinimumSize(14, 23);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
break;
case QButton::ShadowlessSquare:
qButton->setMinimumSize(5, 25);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
break;
case QButton::SmallSquare:
qButton->setMinimumSize(4, 21);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
break;
case QButton::TexturedRounded:
qButton->setMinimumSize(10, 22);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
break;
case QButton::RoundRect:
case QButton::Recessed:
qButton->setMinimumWidth(16);
qButton->setFixedHeight(18);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
break;
case QButton::Disclosure:
qButton->setMinimumWidth(13);
qButton->setFixedHeight(13);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
break;
case QButton::Circular:
qButton->setMinimumSize(16, 16);
qButton->setMaximumHeight(40);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
break;
case QButton::HelpButton:
case QButton::RoundedDisclosure:
qButton->setMinimumWidth(22);
qButton->setFixedHeight(22);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
break;
#ifdef __MAC_10_7
case QButton::Inline:
qButton->setMinimumWidth(10);
qButton->setFixedHeight(16);
qButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
break;
#endif
}
switch(bezelStyle) {
case QButton::Recessed:
[nsButton setButtonType:NSPushOnPushOffButton];
case QButton::Disclosure:
[nsButton setButtonType:NSOnOffButton];
default:
[nsButton setButtonType:NSMomentaryPushInButton];
}
[nsButton setBezelStyle:(__bridge NSBezelStyle)bezelStyle];
}
void clicked()
{
emit qButton->clicked(qButton->isChecked());
}
~QButtonPrivate() {
[[nsButton target] release];
[nsButton setTarget:nil];
}
QButton *qButton;
NSButton *nsButton;
};
@interface QButtonTarget : NSObject
{
@public
QPointer<QButtonPrivate> pimpl;
}
-(void)clicked;
@end
@implementation QButtonTarget
-(void)clicked {
Q_ASSERT(pimpl);
if (pimpl)
pimpl->clicked();
}
@end
QButton::QButton(QWidget *parent, BezelStyle bezelStyle) : QWidget(parent)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSButton *button = [[NSButton alloc] init];
pimpl = new QButtonPrivate(this, button, bezelStyle);
QButtonTarget *target = [[QButtonTarget alloc] init];
target->pimpl = pimpl;
[button setTarget:target];
[button setAction:@selector(clicked)];
setupLayout(button, this);
[button release];
[pool drain];
}
void QButton::setText(const QString &text)
{
Q_ASSERT(pimpl);
if (!pimpl)
return;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pimpl->nsButton setTitle:fromQString(text)];
[pool drain];
}
void QButton::setImage(const QPixmap &image)
{
Q_ASSERT(pimpl);
if (pimpl)
[pimpl->nsButton setImage:fromQPixmap(image)];
}
void QButton::setChecked(bool checked)
{
Q_ASSERT(pimpl);
if (pimpl)
[pimpl->nsButton setState:checked];
}
void QButton::setCheckable(bool checkable)
{
const NSInteger cellMask = checkable ? NSChangeBackgroundCellMask : NSNoCellMask;
Q_ASSERT(pimpl);
if (pimpl)
[[pimpl->nsButton cell] setShowsStateBy:cellMask];
}
bool QButton::isChecked()
{
Q_ASSERT(pimpl);
if (!pimpl)
return false;
return [pimpl->nsButton state];
}

View File

@@ -1,89 +0,0 @@
/*
Copyright (C) 2011 by Mike McQuaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "qbutton.h"
#include <QToolBar>
#include <QToolButton>
#include <QPushButton>
#include <QVBoxLayout>
class QButtonPrivate : public QObject
{
public:
QButtonPrivate(QButton *button, QAbstractButton *abstractButton)
: QObject(button), abstractButton(abstractButton) {}
QPointer<QAbstractButton> abstractButton;
};
QButton::QButton(QWidget *parent, BezelStyle) : QWidget(parent)
{
QAbstractButton *button = 0;
if (qobject_cast<QToolBar*>(parent))
button = new QToolButton(this);
else
button = new QPushButton(this);
connect(button, SIGNAL(clicked()),
this, SIGNAL(clicked()));
pimpl = new QButtonPrivate(this, button);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->addWidget(button);
}
void QButton::setText(const QString &text)
{
Q_ASSERT(pimpl);
if (pimpl)
pimpl->abstractButton->setText(text);
}
void QButton::setImage(const QPixmap &image)
{
Q_ASSERT(pimpl);
if (pimpl)
pimpl->abstractButton->setIcon(image);
}
void QButton::setChecked(bool checked)
{
Q_ASSERT(pimpl);
if (pimpl)
pimpl->abstractButton->setChecked(checked);
}
void QButton::setCheckable(bool checkable)
{
Q_ASSERT(pimpl);
if (pimpl)
pimpl->abstractButton->setCheckable(checkable);
}
bool QButton::isChecked()
{
Q_ASSERT(pimpl);
if (!pimpl)
return false;
return pimpl->abstractButton->isChecked();
}

View File

@@ -1,29 +0,0 @@
#ifndef QPROGRESSINDICATORSPINNING_H
#define QPROGRESSINDICATORSPINNING_H
#include <QWidget>
#include <QPointer>
class QProgressIndicatorSpinningPrivate;
class QProgressIndicatorSpinning : public QWidget
{
Q_OBJECT
public:
// Matches NSProgressIndicatorThickness
enum Thickness {
Default = 14,
Small = 10,
Large = 18,
Aqua = 12
};
explicit QProgressIndicatorSpinning(QWidget *parent,
Thickness thickness = Default);
public slots:
void animate(bool animate = true);
private:
friend class QProgressIndicatorSpinningPrivate;
QPointer<QProgressIndicatorSpinningPrivate> pimpl;
};
#endif // QPROGRESSINDICATORSPINNING_H

View File

@@ -1,70 +0,0 @@
/*
Copyright (C) 2011 by Mike McQuaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "qprogressindicatorspinning.h"
#include "qocoa_mac.h"
#import "Foundation/NSAutoreleasePool.h"
#import "AppKit/NSProgressIndicator.h"
class QProgressIndicatorSpinningPrivate : public QObject
{
public:
QProgressIndicatorSpinningPrivate(QProgressIndicatorSpinning *qProgressIndicatorSpinning,
NSProgressIndicator *nsProgressIndicator)
: QObject(qProgressIndicatorSpinning), nsProgressIndicator(nsProgressIndicator) {}
NSProgressIndicator *nsProgressIndicator;
};
QProgressIndicatorSpinning::QProgressIndicatorSpinning(QWidget *parent,
Thickness thickness)
: QWidget(parent)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSProgressIndicator *progress = [[NSProgressIndicator alloc] init];
[progress setStyle:NSProgressIndicatorSpinningStyle];
pimpl = new QProgressIndicatorSpinningPrivate(this, progress);
setupLayout(progress, this);
setFixedSize(thickness, thickness);
[progress release];
[pool drain];
}
void QProgressIndicatorSpinning::animate(bool animate)
{
Q_ASSERT(pimpl);
if (!pimpl)
return;
if (animate)
[pimpl->nsProgressIndicator startAnimation:nil];
else
[pimpl->nsProgressIndicator stopAnimation:nil];
}

View File

@@ -1,72 +0,0 @@
/*
Copyright (C) 2011 by Mike McQuaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "qprogressindicatorspinning.h"
#include <QVBoxLayout>
#include <QMovie>
#include <QLabel>
class QProgressIndicatorSpinningPrivate : public QObject
{
public:
QProgressIndicatorSpinningPrivate(QProgressIndicatorSpinning *qProgressIndicatorSpinning,
QMovie *movie)
: QObject(qProgressIndicatorSpinning), movie(movie) {}
QPointer<QMovie> movie;
};
QProgressIndicatorSpinning::QProgressIndicatorSpinning(QWidget *parent,
Thickness thickness)
: QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
QSize size(thickness, thickness);
QMovie *movie = new QMovie(this);
movie->setFileName(":/Qocoa/qprogressindicatorspinning_nonmac.gif");
movie->setScaledSize(size);
// Roughly match OSX speed.
movie->setSpeed(200);
pimpl = new QProgressIndicatorSpinningPrivate(this, movie);
QLabel *label = new QLabel(this);
label->setMovie(movie);
layout->addWidget(label);
setFixedSize(size);
}
void QProgressIndicatorSpinning::animate(bool animate)
{
Q_ASSERT(pimpl && pimpl->movie);
if (!(pimpl && pimpl->movie))
return;
if (animate)
pimpl->movie->start();
else
pimpl->movie->stop();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -1,5 +0,0 @@
<RCC>
<qresource prefix="/Qocoa">
<file>qprogressindicatorspinning_nonmac.gif</file>
</qresource>
</RCC>

View File

@@ -1,7 +0,0 @@
<RCC>
<qresource prefix="/Qocoa">
<file>qsearchfield_nonmac_clear.png</file>
<file>qsearchfield_nonmac_magnifier_menu.png</file>
<file>qsearchfield_nonmac_magnifier.png</file>
</qresource>
</RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 439 B

View File

@@ -1,8 +1,20 @@
cmake_minimum_required(VERSION 2.8.11)
include(CheckIncludeFiles)
include(CheckFunctionExists)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -Wall -Woverloaded-virtual -Wno-sign-compare -Wno-deprecated-declarations -Wno-unused-local-typedefs -fpermissive")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -Wall -Woverloaded-virtual -Wno-sign-compare -fpermissive")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wpedantic")
endif()
if(CMAKE_VERSION VERSION_GREATER 3.0)
check_function_exists(geteuid HAVE_GETEUID)
check_function_exists(getpwuid HAVE_GETPWUID)
endif()
set(SINGLEAPP-SOURCES singleapplication.cpp singleapplication_p.cpp)
set(SINGLEAPP-MOC-HEADERS singleapplication.h singleapplication_p.h)
@@ -15,3 +27,6 @@ set(SINGLECOREAPP-MOC-HEADERS singlecoreapplication.h singlecoreapplication_p.h)
QT5_WRAP_CPP(SINGLECOREAPP-SOURCES-MOC ${SINGLECOREAPP-MOC-HEADERS})
ADD_LIBRARY(singlecoreapplication STATIC ${SINGLECOREAPP-SOURCES} ${SINGLECOREAPP-SOURCES-MOC})
target_link_libraries(singlecoreapplication Qt5::Core Qt5::Widgets Qt5::Network)
configure_file(config.h.in "${CMAKE_CURRENT_BINARY_DIR}/config.h")
include_directories(${CMAKE_CURRENT_BINARY_DIR})

View File

@@ -0,0 +1,2 @@
#cmakedefine HAVE_GETEUID
#cmakedefine HAVE_GETPWUID

View File

@@ -20,156 +20,165 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <QApplication>
#include <QtCore/QTime>
#include <QtCore/QThread>
#include <QtCore/QDateTime>
#include <QtCore/QByteArray>
#include <QtCore/QSharedMemory>
//
// W A R N I N G !!!
// -----------------
//
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#include <QtGlobal>
#include <QCoreApplication>
#include <QThread>
#include <QSharedMemory>
#include <QByteArray>
#include <QDateTime>
#include <QTime>
#include "singleapplication.h"
#include "singleapplication_p.h"
/**
* @brief Constructor. Checks and fires up LocalServer or closes the program
* if another instance already exists
* @brief Constructor.
* Checks and fires up LocalServer or closes the program if another instance already exists
* @param argc
* @param argv
* @param {bool} allowSecondaryInstances
*/
SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSecondary, Options options, int timeout )
: app_t( argc, argv ), d_ptr( new SingleApplicationPrivate( this ) )
{
Q_D(SingleApplication);
SingleApplication::SingleApplication(int &argc, char *argv[], bool allowSecondary, Options options, int timeout)
: app_t(argc, argv), d_ptr(new SingleApplicationPrivate(this)) {
// Store the current mode of the program
d->options = options;
Q_D(SingleApplication);
// Generating an application ID used for identifying the shared memory
// block and QLocalServer
d->genBlockServerName();
// Store the current mode of the program
d->options = options;
// Generating an application ID used for identifying the shared memory block and QLocalServer
d->genBlockServerName();
#ifdef Q_OS_UNIX
// By explicitly attaching it and then deleting it we make sure that the
// memory is deleted even after the process has crashed on Unix.
d->memory = new QSharedMemory( d->blockServerName );
d->memory->attach();
delete d->memory;
// By explicitly attaching it and then deleting it we make sure that the
// memory is deleted even after the process has crashed on Unix.
d->memory = new QSharedMemory(d->blockServerName);
d->memory->attach();
delete d->memory;
#endif
// Guarantee thread safe behaviour with a shared memory block.
d->memory = new QSharedMemory( d->blockServerName );
// Guarantee thread safe behaviour with a shared memory block.
d->memory = new QSharedMemory(d->blockServerName);
// Create a shared memory block
if( d->memory->create( sizeof( InstancesInfo ) ) ) {
// Initialize the shared memory block
d->memory->lock();
d->initializeMemoryBlock();
d->memory->unlock();
} else {
// Attempt to attach to the memory segment
if( ! d->memory->attach() ) {
qCritical() << "SingleApplication: Unable to attach to shared memory block.";
qCritical() << d->memory->errorString();
delete d;
::exit( EXIT_FAILURE );
}
// Create a shared memory block
if (d->memory->create(sizeof(InstancesInfo))) {
// Initialize the shared memory block
d->memory->lock();
d->initializeMemoryBlock();
d->memory->unlock();
}
else {
// Attempt to attach to the memory segment
if (! d->memory->attach()) {
qCritical() << "SingleApplication: Unable to attach to shared memory block.";
qCritical() << d->memory->errorString();
delete d;
::exit(EXIT_FAILURE);
}
}
InstancesInfo* inst = static_cast<InstancesInfo*>( d->memory->data() );
QTime time;
time.start();
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data());
QTime time;
time.start();
// Make sure the shared memory block is initialised and in consistent state
while( true ) {
d->memory->lock();
// Make sure the shared memory block is initialised and in consistent state
while (true) {
d->memory->lock();
if( d->blockChecksum() == inst->checksum ) break;
if (d->blockChecksum() == inst->checksum) break;
if( time.elapsed() > 5000 ) {
qWarning() << "SingleApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure.";
d->initializeMemoryBlock();
}
d->memory->unlock();
// Random sleep here limits the probability of a collision between two racing apps
qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() );
QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ) );
}
if( inst->primary == false) {
d->startPrimary();
d->memory->unlock();
return;
}
// Check if another instance can be started
if( allowSecondary ) {
inst->secondary += 1;
inst->checksum = d->blockChecksum();
d->instanceNumber = inst->secondary;
d->startSecondary();
if( d->options & Mode::SecondaryNotification ) {
d->connectToPrimary( timeout, SingleApplicationPrivate::SecondaryInstance );
}
d->memory->unlock();
return;
if (time.elapsed() > 5000) {
qWarning() << "SingleApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure.";
d->initializeMemoryBlock();
}
d->memory->unlock();
d->connectToPrimary( timeout, SingleApplicationPrivate::NewInstance );
// Random sleep here limits the probability of a collision between two racing apps
qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max());
QThread::sleep(8 + static_cast <unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10));
}
delete d;
if (inst->primary == false) {
d->startPrimary();
d->memory->unlock();
return;
}
// Check if another instance can be started
if (allowSecondary) {
inst->secondary += 1;
inst->checksum = d->blockChecksum();
d->instanceNumber = inst->secondary;
d->startSecondary();
if (d->options & Mode::SecondaryNotification) {
d->connectToPrimary(timeout, SingleApplicationPrivate::SecondaryInstance);
}
d->memory->unlock();
return;
}
d->memory->unlock();
d->connectToPrimary(timeout, SingleApplicationPrivate::NewInstance);
delete d;
::exit(EXIT_SUCCESS);
::exit( EXIT_SUCCESS );
}
/**
* @brief Destructor
*/
SingleApplication::~SingleApplication()
{
Q_D(SingleApplication);
delete d;
SingleApplication::~SingleApplication() {
Q_D(SingleApplication);
delete d;
}
bool SingleApplication::isPrimary()
{
Q_D(SingleApplication);
return d->server != nullptr;
bool SingleApplication::isPrimary() {
Q_D(SingleApplication);
return d->server != nullptr;
}
bool SingleApplication::isSecondary()
{
Q_D(SingleApplication);
return d->server == nullptr;
bool SingleApplication::isSecondary() {
Q_D(SingleApplication);
return d->server == nullptr;
}
quint32 SingleApplication::instanceId()
{
Q_D(SingleApplication);
return d->instanceNumber;
quint32 SingleApplication::instanceId() {
Q_D(SingleApplication);
return d->instanceNumber;
}
qint64 SingleApplication::primaryPid()
{
Q_D(SingleApplication);
return d->primaryPid();
qint64 SingleApplication::primaryPid() {
Q_D(SingleApplication);
return d->primaryPid();
}
bool SingleApplication::sendMessage( QByteArray message, int timeout )
{
Q_D(SingleApplication);
bool SingleApplication::sendMessage(QByteArray message, int timeout) {
// Nobody to connect to
if( isPrimary() ) return false;
Q_D(SingleApplication);
// Make sure the socket is connected
d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect );
// Nobody to connect to
if (isPrimary()) return false;
// Make sure the socket is connected
d->connectToPrimary(timeout, SingleApplicationPrivate::Reconnect);
d->socket->write(message);
bool dataWritten = d->socket->waitForBytesWritten(timeout);
d->socket->flush();
return dataWritten;
d->socket->write( message );
bool dataWritten = d->socket->flush();
d->socket->waitForBytesWritten( timeout );
return dataWritten;
}

View File

@@ -20,12 +20,23 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// W A R N I N G !!!
// -----------------
//
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#ifndef SINGLEAPPLICATION_H
#define SINGLEAPPLICATION_H
#include <QtCore/QtGlobal>
#include <QtGlobal>
#include <QApplication>
#include <QtNetwork/QLocalSocket>
#include <QLocalSocket>
class SingleApplicationPrivate;
@@ -34,95 +45,95 @@ class SingleApplicationPrivate;
* Application
* @see QCoreApplication
*/
class SingleApplication : public QApplication
{
Q_OBJECT
class SingleApplication : public QApplication {
Q_OBJECT
typedef QApplication app_t;
typedef QApplication app_t;
public:
/**
* @brief Mode of operation of SingleApplication.
* Whether the block should be user-wide or system-wide and whether the
* primary instance should be notified when a secondary instance had been
* started.
* @note Operating system can restrict the shared memory blocks to the same
* user, in which case the User/System modes will have no effect and the
* block will be user wide.
* @enum
*/
enum Mode {
User = 1 << 0,
System = 1 << 1,
SecondaryNotification = 1 << 2,
ExcludeAppVersion = 1 << 3,
ExcludeAppPath = 1 << 4
};
Q_DECLARE_FLAGS(Options, Mode)
/**
* @brief Mode of operation of SingleApplication.
* Whether the block should be user-wide or system-wide and whether the
* primary instance should be notified when a secondary instance had been
* started.
* @note Operating system can restrict the shared memory blocks to the same
* user, in which case the User/System modes will have no effect and the
* block will be user wide.
* @enum
*/
enum Mode {
User = 1 << 0,
System = 1 << 1,
SecondaryNotification = 1 << 2,
ExcludeAppVersion = 1 << 3,
ExcludeAppPath = 1 << 4
};
Q_DECLARE_FLAGS(Options, Mode)
/**
* @brief Intitializes a SingleApplication instance with argc command line
* arguments in argv
* @arg {int &} argc - Number of arguments in argv
* @arg {const char *[]} argv - Supplied command line arguments
* @arg {bool} allowSecondary - Whether to start the instance as secondary
* if there is already a primary instance.
* @arg {Mode} mode - Whether for the SingleApplication block to be applied
* User wide or System wide.
* @arg {int} timeout - Timeout to wait in miliseconds.
* @note argc and argv may be changed as Qt removes arguments that it
* recognizes
* @note Mode::SecondaryNotification only works if set on both the primary
* instance and the secondary instance.
* @note The timeout is just a hint for the maximum time of blocking
* operations. It does not guarantee that the SingleApplication
* initialisation will be completed in given time, though is a good hint.
* Usually 4*timeout would be the worst case (fail) scenario.
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/
explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleApplication();
/**
* @brief Intitializes a SingleApplication instance with argc command line
* arguments in argv
* @arg {int &} argc - Number of arguments in argv
* @arg {const char *[]} argv - Supplied command line arguments
* @arg {bool} allowSecondary - Whether to start the instance as secondary
* if there is already a primary instance.
* @arg {Mode} mode - Whether for the SingleApplication block to be applied
* User wide or System wide.
* @arg {int} timeout - Timeout to wait in milliseconds.
* @note argc and argv may be changed as Qt removes arguments that it
* recognizes
* @note Mode::SecondaryNotification only works if set on both the primary
* instance and the secondary instance.
* @note The timeout is just a hint for the maximum time of blocking
* operations. It does not guarantee that the SingleApplication
* initialisation will be completed in given time, though is a good hint.
* Usually 4*timeout would be the worst case (fail) scenario.
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/
explicit SingleApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleApplication();
/**
* @brief Returns if the instance is the primary instance
* @returns {bool}
*/
bool isPrimary();
/**
* @brief Returns if the instance is the primary instance
* @returns {bool}
*/
bool isPrimary();
/**
* @brief Returns if the instance is a secondary instance
* @returns {bool}
*/
bool isSecondary();
/**
* @brief Returns if the instance is a secondary instance
* @returns {bool}
*/
bool isSecondary();
/**
* @brief Returns a unique identifier for the current instance
* @returns {qint32}
*/
quint32 instanceId();
/**
* @brief Returns a unique identifier for the current instance
* @returns {qint32}
*/
quint32 instanceId();
/**
* @brief Returns the process ID (PID) of the primary instance
* @returns {qint64}
*/
qint64 primaryPid();
/**
* @brief Returns the process ID (PID) of the primary instance
* @returns {qint64}
*/
qint64 primaryPid();
/**
* @brief Sends a message to the primary instance. Returns true on success.
* @param {int} timeout - Timeout for connecting
* @returns {bool}
* @note sendMessage() will return false if invoked from the primary
* instance.
*/
bool sendMessage( QByteArray message, int timeout = 100 );
/**
* @brief Sends a message to the primary instance. Returns true on success.
* @param {int} timeout - Timeout for connecting
* @returns {bool}
* @note sendMessage() will return false if invoked from the primary
* instance.
*/
bool sendMessage( QByteArray message, int timeout = 1000 );
Q_SIGNALS:
void instanceStarted();
void receivedMessage( quint32 instanceId, QByteArray message );
signals:
void instanceStarted();
void receivedMessage( quint32 instanceId, QByteArray message );
private:
SingleApplicationPrivate *d_ptr;
Q_DECLARE_PRIVATE(SingleApplication)
private:
SingleApplicationPrivate *d_ptr;
Q_DECLARE_PRIVATE(SingleApplication)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(SingleApplication::Options)

View File

@@ -24,381 +24,386 @@
// W A R N I N G !!!
// -----------------
//
// This file is not part of the SingleApplication API. It is used purely as an
// implementation detail. This header file may change from version to
// version without notice, or may even be removed.
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#include "config.h"
#include <QtGlobal>
#include <cstdlib>
#include <cstddef>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QByteArray>
#include <QtCore/QSemaphore>
#include <QtCore/QDataStream>
#include <QtCore/QStandardPaths>
#include <QtCore/QCryptographicHash>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
#ifdef Q_OS_UNIX
# include <unistd.h>
# include <sys/types.h>
# include <pwd.h>
#endif
#include <QDir>
#include <QByteArray>
#include <QDataStream>
#include <QCryptographicHash>
#include <QLocalServer>
#include <QLocalSocket>
#include "singleapplication.h"
#include "singleapplication_p.h"
#ifdef Q_OS_WIN
#include <windows.h>
#include <lmcons.h>
# include <windows.h>
# include <lmcons.h>
#endif
SingleApplicationPrivate::SingleApplicationPrivate( SingleApplication *q_ptr )
: q_ptr( q_ptr )
{
server = nullptr;
socket = nullptr;
memory = nullptr;
instanceNumber = -1;
}
SingleApplicationPrivate::SingleApplicationPrivate(SingleApplication *q_ptr)
: q_ptr(q_ptr),
memory(nullptr),
socket(nullptr),
server(nullptr),
instanceNumber(-1)
{}
SingleApplicationPrivate::~SingleApplicationPrivate()
{
if( socket != nullptr ) {
socket->close();
delete socket;
}
SingleApplicationPrivate::~SingleApplicationPrivate() {
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
if( server != nullptr ) {
server->close();
delete server;
inst->primary = false;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
memory->unlock();
if (socket != nullptr) {
socket->close();
delete socket;
}
delete memory;
}
void SingleApplicationPrivate::genBlockServerName()
{
QCryptographicHash appData( QCryptographicHash::Sha256 );
appData.addData( "SingleApplication", 17 );
appData.addData( SingleApplication::app_t::applicationName().toUtf8() );
appData.addData( SingleApplication::app_t::organizationName().toUtf8() );
appData.addData( SingleApplication::app_t::organizationDomain().toUtf8() );
if( ! (options & SingleApplication::Mode::ExcludeAppVersion) ) {
appData.addData( SingleApplication::app_t::applicationVersion().toUtf8() );
}
if( ! (options & SingleApplication::Mode::ExcludeAppPath) ) {
#ifdef Q_OS_WIN
appData.addData( SingleApplication::app_t::applicationFilePath().toLower().toUtf8() );
#else
appData.addData( SingleApplication::app_t::applicationFilePath().toUtf8() );
#endif
}
// User level block requires a user specific data in the hash
if( options & SingleApplication::Mode::User ) {
#ifdef Q_OS_WIN
wchar_t username [ UNLEN + 1 ];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if( GetUserNameW( username, &usernameLength ) ) {
appData.addData( QString::fromWCharArray(username).toUtf8() );
} else {
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
}
#endif
#ifdef Q_OS_UNIX
QProcess process;
process.start( "whoami" );
if( process.waitForFinished( 100 ) &&
process.exitCode() == QProcess::NormalExit) {
appData.addData( process.readLine() );
} else {
appData.addData(
QDir(
QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first()
).absolutePath().toUtf8()
);
}
#endif
}
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with
// server naming requirements.
blockServerName = appData.result().toBase64().replace("/", "_");
}
void SingleApplicationPrivate::initializeMemoryBlock()
{
InstancesInfo* inst = static_cast<InstancesInfo*>( memory->data() );
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
if (server != nullptr) {
server->close();
delete server;
inst->primary = false;
inst->secondary = 0;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
memory->unlock();
delete memory;
}
void SingleApplicationPrivate::startPrimary()
{
Q_Q(SingleApplication);
void SingleApplicationPrivate::genBlockServerName() {
// Successful creation means that no main process exists
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer( blockServerName );
server = new QLocalServer();
QCryptographicHash appData(QCryptographicHash::Sha256);
appData.addData("SingleApplication", 17);
appData.addData(SingleApplication::app_t::applicationName().toUtf8());
appData.addData(SingleApplication::app_t::organizationName().toUtf8());
appData.addData(SingleApplication::app_t::organizationDomain().toUtf8());
// Restrict access to the socket according to the
// SingleApplication::Mode::User flag on User level or no restrictions
if( options & SingleApplication::Mode::User ) {
server->setSocketOptions( QLocalServer::UserAccessOption );
} else {
server->setSocketOptions( QLocalServer::WorldAccessOption );
if (!(options & SingleApplication::Mode::ExcludeAppVersion)) {
appData.addData(SingleApplication::app_t::applicationVersion().toUtf8());
}
if (! (options & SingleApplication::Mode::ExcludeAppPath)) {
#ifdef Q_OS_WIN
appData.addData(SingleApplication::app_t::applicationFilePath().toLower().toUtf8());
#else
appData.addData(SingleApplication::app_t::applicationFilePath().toUtf8());
#endif
}
// User level block requires a user specific data in the hash
if (options & SingleApplication::Mode::User) {
#ifdef Q_OS_UNIX
QByteArray username;
#if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID)
uid_t uid = geteuid();
if (uid != -1) {
struct passwd *pw = getpwuid(uid);
if (pw) {
username = pw->pw_name;
}
}
#endif
if (username.isEmpty()) username = qgetenv("USER");
appData.addData(username);
#endif
#ifdef Q_OS_WIN
wchar_t username [ UNLEN + 1 ];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if (GetUserNameW(username, &usernameLength)) {
appData.addData(QString::fromWCharArray(username).toUtf8());
}
else {
appData.addData(qgetenv("USERNAME"));
}
#endif
}
server->listen( blockServerName );
QObject::connect(
server,
&QLocalServer::newConnection,
this,
&SingleApplicationPrivate::slotConnectionEstablished
);
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
blockServerName = appData.result().toBase64().replace("/", "_");
// Reset the number of connections
InstancesInfo* inst = static_cast <InstancesInfo*>( memory->data() );
inst->primary = true;
inst->primaryPid = q->applicationPid();
inst->checksum = blockChecksum();
instanceNumber = 0;
}
void SingleApplicationPrivate::startSecondary()
{
void SingleApplicationPrivate::initializeMemoryBlock() {
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
inst->primary = false;
inst->secondary = 0;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
void SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
{
// Connect to the Local Server of the Primary Instance if not already
// connected.
if( socket == nullptr ) {
socket = new QLocalSocket();
}
void SingleApplicationPrivate::startPrimary() {
// If already connected - we are done;
if( socket->state() == QLocalSocket::ConnectedState )
return;
Q_Q(SingleApplication);
// If not connect
if( socket->state() == QLocalSocket::UnconnectedState ||
socket->state() == QLocalSocket::ClosingState ) {
socket->connectToServer( blockServerName );
}
// Successful creation means that no main process exists
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer(blockServerName);
server = new QLocalServer();
// Wait for being connected
if( socket->state() == QLocalSocket::ConnectingState ) {
socket->waitForConnected( msecs );
}
// Restrict access to the socket according to the
// SingleApplication::Mode::User flag on User level or no restrictions
if (options & SingleApplication::Mode::User) {
server->setSocketOptions(QLocalServer::UserAccessOption);
}
else {
server->setSocketOptions(QLocalServer::WorldAccessOption);
}
// Initialisation message according to the SingleApplication protocol
if( socket->state() == QLocalSocket::ConnectedState ) {
// Notify the parent that a new instance had been started;
QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
server->listen(blockServerName);
QObject::connect(server, &QLocalServer::newConnection, this, &SingleApplicationPrivate::slotConnectionEstablished);
// Reset the number of connections
InstancesInfo* inst = static_cast <InstancesInfo*>(memory->data());
inst->primary = true;
inst->primaryPid = q->applicationPid();
inst->checksum = blockChecksum();
instanceNumber = 0;
}
void SingleApplicationPrivate::startSecondary() {}
void SingleApplicationPrivate::connectToPrimary(int msecs, ConnectionType connectionType) {
// Connect to the Local Server of the Primary Instance if not already connected.
if (socket == nullptr) {
socket = new QLocalSocket();
}
// If already connected - we are done;
if (socket->state() == QLocalSocket::ConnectedState)
return;
// If not connect
if (socket->state() == QLocalSocket::UnconnectedState ||
socket->state() == QLocalSocket::ClosingState) {
socket->connectToServer(blockServerName);
}
// Wait for being connected
if (socket->state() == QLocalSocket::ConnectingState) {
socket->waitForConnected(msecs);
}
// Initialisation message according to the SingleApplication protocol
if (socket->state() == QLocalSocket::ConnectedState) {
// Notify the parent that a new instance had been started;
QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
writeStream.setVersion(QDataStream::Qt_5_6);
writeStream.setVersion(QDataStream::Qt_5_6);
#endif
writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType);
writeStream << instanceNumber;
quint16 checksum = qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length()));
writeStream << checksum;
writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType);
writeStream << instanceNumber;
quint16 checksum = qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length()));
writeStream << checksum;
// The header indicates the message length that follows
QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly);
// The header indicates the message length that follows
QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6);
headerStream.setVersion(QDataStream::Qt_5_6);
#endif
headerStream << static_cast <quint64>( initMsg.length() );
headerStream << static_cast <quint64>(initMsg.length());
socket->write(header);
socket->write(initMsg);
socket->flush();
socket->waitForBytesWritten(msecs);
}
socket->write( header );
socket->write( initMsg );
socket->flush();
socket->waitForBytesWritten( msecs );
}
}
quint16 SingleApplicationPrivate::blockChecksum()
{
return qChecksum(
static_cast <const char *>( memory->data() ),
offsetof( InstancesInfo, checksum )
);
quint16 SingleApplicationPrivate::blockChecksum() {
return qChecksum(static_cast <const char *>(memory->data()), offsetof(InstancesInfo, checksum));
}
qint64 SingleApplicationPrivate::primaryPid()
{
qint64 pid;
qint64 SingleApplicationPrivate::primaryPid() {
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>( memory->data() );
pid = inst->primaryPid;
memory->unlock();
qint64 pid;
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
pid = inst->primaryPid;
memory->unlock();
return pid;
return pid;
}
/**
* @brief Executed when a connection has been made to the LocalServer
*/
void SingleApplicationPrivate::slotConnectionEstablished()
{
QLocalSocket *nextConnSocket = server->nextPendingConnection();
connectionMap.insert(nextConnSocket, ConnectionInfo());
void SingleApplicationPrivate::slotConnectionEstablished() {
QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
Q_EMIT this->slotClientConnectionClosed( nextConnSocket, info.instanceId );
}
);
QLocalSocket *nextConnSocket = server->nextPendingConnection();
connectionMap.insert(nextConnSocket, ConnectionInfo());
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
[nextConnSocket, this](){
connectionMap.remove(nextConnSocket);
nextConnSocket->deleteLater();
}
);
QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
}
);
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
[nextConnSocket, this](){
connectionMap.remove(nextConnSocket);
nextConnSocket->deleteLater();
}
);
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
switch(info.stage) {
case StageHeader:
readInitMessageHeader(nextConnSocket);
break;
case StageBody:
readInitMessageBody(nextConnSocket);
break;
case StageConnected:
Q_EMIT this->slotDataAvailable(nextConnSocket, info.instanceId);
break;
default:
break;
};
}
);
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
switch(info.stage) {
case StageHeader:
readInitMessageHeader(nextConnSocket);
break;
case StageBody:
readInitMessageBody(nextConnSocket);
break;
case StageConnected:
Q_EMIT this->slotDataAvailable( nextConnSocket, info.instanceId );
break;
default:
break;
};
}
);
}
void SingleApplicationPrivate::readInitMessageHeader( QLocalSocket *sock )
{
if (!connectionMap.contains( sock )) {
return;
}
void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
if( sock->bytesAvailable() < ( qint64 )sizeof( quint64 ) ) {
return;
}
if (!connectionMap.contains(sock)) {
return;
}
QDataStream headerStream( sock );
if (sock->bytesAvailable() < (qint64) sizeof(quint64)) {
return;
}
QDataStream headerStream(sock);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion( QDataStream::Qt_5_6 );
headerStream.setVersion(QDataStream::Qt_5_6);
#endif
// Read the header to know the message length
quint64 msgLen = 0;
headerStream >> msgLen;
ConnectionInfo &info = connectionMap[sock];
info.stage = StageBody;
info.msgLen = msgLen;
// Read the header to know the message length
quint64 msgLen = 0;
headerStream >> msgLen;
ConnectionInfo &info = connectionMap[sock];
info.stage = StageBody;
info.msgLen = msgLen;
if (sock->bytesAvailable() >= (qint64) msgLen) {
readInitMessageBody(sock);
}
if ( sock->bytesAvailable() >= (qint64) msgLen ) {
readInitMessageBody( sock );
}
}
void SingleApplicationPrivate::readInitMessageBody( QLocalSocket *sock )
{
Q_Q(SingleApplication);
void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
if (!connectionMap.contains( sock )) {
return;
}
Q_Q(SingleApplication);
ConnectionInfo &info = connectionMap[sock];
if( sock->bytesAvailable() < ( qint64 )info.msgLen ) {
return;
}
if (!connectionMap.contains(sock)) {
return;
}
// Read the message body
QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes);
ConnectionInfo &info = connectionMap[sock];
if (sock->bytesAvailable() < (qint64)info.msgLen) {
return;
}
// Read the message body
QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
readStream.setVersion( QDataStream::Qt_5_6 );
readStream.setVersion(QDataStream::Qt_5_6);
#endif
// server name
QByteArray latin1Name;
readStream >> latin1Name;
// server name
QByteArray latin1Name;
readStream >> latin1Name;
// connection type
ConnectionType connectionType = InvalidConnection;
quint8 connTypeVal = InvalidConnection;
readStream >> connTypeVal;
connectionType = static_cast <ConnectionType>( connTypeVal );
// connection type
ConnectionType connectionType = InvalidConnection;
quint8 connTypeVal = InvalidConnection;
readStream >> connTypeVal;
connectionType = static_cast <ConnectionType>(connTypeVal);
// instance id
quint32 instanceId = 0;
readStream >> instanceId;
// instance id
quint32 instanceId = 0;
readStream >> instanceId;
// checksum
quint16 msgChecksum = 0;
readStream >> msgChecksum;
// checksum
quint16 msgChecksum = 0;
readStream >> msgChecksum;
const quint16 actualChecksum = qChecksum( msgBytes.constData(), static_cast<quint32>( msgBytes.length() - sizeof( quint16 ) ) );
const quint16 actualChecksum = qChecksum(msgBytes.constData(), static_cast<quint32>(msgBytes.length() - sizeof(quint16)));
bool isValid = readStream.status() == QDataStream::Ok &&
QLatin1String(latin1Name) == blockServerName &&
msgChecksum == actualChecksum;
bool isValid = readStream.status() == QDataStream::Ok && QLatin1String(latin1Name) == blockServerName && msgChecksum == actualChecksum;
if( !isValid ) {
sock->close();
return;
}
if (!isValid) {
sock->close();
return;
}
info.instanceId = instanceId;
info.stage = StageConnected;
info.instanceId = instanceId;
info.stage = StageConnected;
if( connectionType == NewInstance ||
( connectionType == SecondaryInstance &&
options & SingleApplication::Mode::SecondaryNotification ) )
{
Q_EMIT q->instanceStarted();
}
if (connectionType == NewInstance || (connectionType == SecondaryInstance && options & SingleApplication::Mode::SecondaryNotification)) {
Q_EMIT q->instanceStarted();
}
if (sock->bytesAvailable() > 0) {
Q_EMIT this->slotDataAvailable(sock, instanceId);
}
if (sock->bytesAvailable() > 0) {
Q_EMIT this->slotDataAvailable( sock, instanceId );
}
}
void SingleApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
{
Q_Q(SingleApplication);
Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() );
void SingleApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, quint32 instanceId) {
Q_Q(SingleApplication);
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
}
void SingleApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
{
if( closedSocket->bytesAvailable() > 0 )
Q_EMIT slotDataAvailable( closedSocket, instanceId );
void SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, quint32 instanceId) {
if (closedSocket->bytesAvailable() > 0)
Q_EMIT slotDataAvailable(closedSocket, instanceId);
}

View File

@@ -24,76 +24,80 @@
// W A R N I N G !!!
// -----------------
//
// This file is not part of the SingleApplication API. It is used purely as an
// implementation detail. This header file may change from version to
// version without notice, or may even be removed.
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#ifndef SINGLEAPPLICATION_P_H
#define SINGLEAPPLICATION_P_H
#include <QtCore/QSharedMemory>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
#include <QtGlobal>
#include <QLocalSocket>
#include <QLocalServer>
#include <QSharedMemory>
#include <QMap>
#include "singleapplication.h"
struct InstancesInfo {
bool primary;
quint32 secondary;
qint64 primaryPid;
quint16 checksum;
bool primary;
quint32 secondary;
qint64 primaryPid;
quint16 checksum;
};
struct ConnectionInfo {
explicit ConnectionInfo() :
msgLen(0), instanceId(0), stage(0) {}
qint64 msgLen;
quint32 instanceId;
quint8 stage;
explicit ConnectionInfo() : msgLen(0), instanceId(0), stage(0) {}
qint64 msgLen;
quint32 instanceId;
quint8 stage;
};
class SingleApplicationPrivate : public QObject {
Q_OBJECT
public:
enum ConnectionType : quint8 {
InvalidConnection = 0,
NewInstance = 1,
SecondaryInstance = 2,
Reconnect = 3
};
enum ConnectionStage : quint8 {
StageHeader = 0,
StageBody = 1,
StageConnected = 2,
};
Q_DECLARE_PUBLIC(SingleApplication)
Q_OBJECT
public:
enum ConnectionType : quint8 {
InvalidConnection = 0,
NewInstance = 1,
SecondaryInstance = 2,
Reconnect = 3
};
enum ConnectionStage : quint8 {
StageHeader = 0,
StageBody = 1,
StageConnected = 2,
};
Q_DECLARE_PUBLIC(SingleApplication)
SingleApplicationPrivate( SingleApplication *q_ptr );
~SingleApplicationPrivate();
SingleApplicationPrivate( SingleApplication *q_ptr );
~SingleApplicationPrivate();
void genBlockServerName();
void initializeMemoryBlock();
void startPrimary();
void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType );
quint16 blockChecksum();
qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
void genBlockServerName();
void initializeMemoryBlock();
void startPrimary();
void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType );
quint16 blockChecksum();
qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
SingleApplication *q_ptr;
QSharedMemory *memory;
QLocalSocket *socket;
QLocalServer *server;
quint32 instanceNumber;
QString blockServerName;
SingleApplication::Options options;
QMap<QLocalSocket*, ConnectionInfo> connectionMap;
SingleApplication *q_ptr;
QSharedMemory *memory;
QLocalSocket *socket;
QLocalServer *server;
quint32 instanceNumber;
QString blockServerName;
SingleApplication::Options options;
QMap<QLocalSocket*, ConnectionInfo> connectionMap;
public Q_SLOTS:
void slotConnectionEstablished();
void slotDataAvailable( QLocalSocket*, quint32 );
void slotClientConnectionClosed( QLocalSocket*, quint32 );
public slots:
void slotConnectionEstablished();
void slotDataAvailable(QLocalSocket*, quint32);
void slotClientConnectionClosed(QLocalSocket*, quint32);
};
#endif // SINGLEAPPLICATION_P_H
#endif // SINGLEAPPLICATION_P_H

View File

@@ -20,12 +20,24 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// W A R N I N G !!!
// -----------------
//
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore/QTime>
#include <QtCore/QThread>
#include <QtCore/QDateTime>
#include <QtCore/QByteArray>
#include <QtCore/QSharedMemory>
#include <QThread>
#include <QSharedMemory>
#include <QByteArray>
#include <QDateTime>
#include <QTime>
#include "singlecoreapplication.h"
#include "singlecoreapplication_p.h"
@@ -37,139 +49,137 @@
* @param argv
* @param {bool} allowSecondaryInstances
*/
SingleCoreApplication::SingleCoreApplication( int &argc, char *argv[], bool allowSecondary, Options options, int timeout )
: app_t( argc, argv ), d_ptr( new SingleCoreApplicationPrivate( this ) )
{
Q_D(SingleCoreApplication);
SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allowSecondary, Options options, int timeout)
: app_t(argc, argv), d_ptr(new SingleCoreApplicationPrivate(this)) {
// Store the current mode of the program
d->options = options;
Q_D(SingleCoreApplication);
// Generating an application ID used for identifying the shared memory
// block and QLocalServer
d->genBlockServerName();
// Store the current mode of the program
d->options = options;
// Generating an application ID used for identifying the shared memory
// block and QLocalServer
d->genBlockServerName();
#ifdef Q_OS_UNIX
// By explicitly attaching it and then deleting it we make sure that the
// memory is deleted even after the process has crashed on Unix.
d->memory = new QSharedMemory( d->blockServerName );
d->memory->attach();
delete d->memory;
// By explicitly attaching it and then deleting it we make sure that the
// memory is deleted even after the process has crashed on Unix.
d->memory = new QSharedMemory(d->blockServerName);
d->memory->attach();
delete d->memory;
#endif
// Guarantee thread safe behaviour with a shared memory block.
d->memory = new QSharedMemory( d->blockServerName );
// Guarantee thread safe behaviour with a shared memory block.
d->memory = new QSharedMemory(d->blockServerName);
// Create a shared memory block
if( d->memory->create( sizeof( InstancesInfo ) ) ) {
// Initialize the shared memory block
d->memory->lock();
d->initializeMemoryBlock();
d->memory->unlock();
} else {
// Attempt to attach to the memory segment
if( ! d->memory->attach() ) {
qCritical() << "SingleCoreApplication: Unable to attach to shared memory block.";
qCritical() << d->memory->errorString();
delete d;
::exit( EXIT_FAILURE );
}
// Create a shared memory block
if (d->memory->create(sizeof(InstancesInfo))) {
// Initialize the shared memory block
d->memory->lock();
d->initializeMemoryBlock();
d->memory->unlock();
}
else {
// Attempt to attach to the memory segment
if (!d->memory->attach()) {
qCritical() << "SingleCoreApplication: Unable to attach to shared memory block.";
qCritical() << d->memory->errorString();
delete d;
::exit(EXIT_FAILURE);
}
}
InstancesInfo* inst = static_cast<InstancesInfo*>( d->memory->data() );
QTime time;
time.start();
InstancesInfo* inst = static_cast<InstancesInfo*>(d->memory->data());
QTime time;
time.start();
// Make sure the shared memory block is initialised and in consistent state
while( true ) {
d->memory->lock();
// Make sure the shared memory block is initialised and in consistent state
while (true) {
d->memory->lock();
if( d->blockChecksum() == inst->checksum ) break;
if(d->blockChecksum() == inst->checksum) break;
if( time.elapsed() > 5000 ) {
qWarning() << "SingleCoreApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure.";
d->initializeMemoryBlock();
}
d->memory->unlock();
// Random sleep here limits the probability of a collision between two racing apps
qsrand( QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max() );
QThread::sleep( 8 + static_cast <unsigned long>( static_cast <float>( qrand() ) / RAND_MAX * 10 ) );
}
if( inst->primary == false) {
d->startPrimary();
d->memory->unlock();
return;
}
// Check if another instance can be started
if( allowSecondary ) {
inst->secondary += 1;
inst->checksum = d->blockChecksum();
d->instanceNumber = inst->secondary;
d->startSecondary();
if( d->options & Mode::SecondaryNotification ) {
d->connectToPrimary( timeout, SingleCoreApplicationPrivate::SecondaryInstance );
}
d->memory->unlock();
return;
if (time.elapsed() > 5000) {
qWarning() << "SingleCoreApplication: Shared memory block has been in an inconsistent state from more than 5s. Assuming primary instance failure.";
d->initializeMemoryBlock();
}
d->memory->unlock();
d->connectToPrimary( timeout, SingleCoreApplicationPrivate::NewInstance );
// Random sleep here limits the probability of a collision between two racing apps
qsrand(QDateTime::currentMSecsSinceEpoch() % std::numeric_limits<uint>::max());
QThread::sleep(8 + static_cast <unsigned long>(static_cast <float>(qrand()) / RAND_MAX * 10));
}
delete d;
if (inst->primary == false) {
d->startPrimary();
d->memory->unlock();
return;
}
// Check if another instance can be started
if (allowSecondary) {
inst->secondary += 1;
inst->checksum = d->blockChecksum();
d->instanceNumber = inst->secondary;
d->startSecondary();
if(d->options & Mode::SecondaryNotification) {
d->connectToPrimary(timeout, SingleCoreApplicationPrivate::SecondaryInstance);
}
d->memory->unlock();
return;
}
d->memory->unlock();
d->connectToPrimary(timeout, SingleCoreApplicationPrivate::NewInstance);
delete d;
::exit(EXIT_SUCCESS);
::exit( EXIT_SUCCESS );
}
/**
* @brief Destructor
*/
SingleCoreApplication::~SingleCoreApplication()
{
Q_D(SingleCoreApplication);
delete d;
SingleCoreApplication::~SingleCoreApplication() {
Q_D(SingleCoreApplication);
delete d;
}
bool SingleCoreApplication::isPrimary()
{
Q_D(SingleCoreApplication);
return d->server != nullptr;
bool SingleCoreApplication::isPrimary() {
Q_D(SingleCoreApplication);
return d->server != nullptr;
}
bool SingleCoreApplication::isSecondary()
{
Q_D(SingleCoreApplication);
return d->server == nullptr;
bool SingleCoreApplication::isSecondary() {
Q_D(SingleCoreApplication);
return d->server == nullptr;
}
quint32 SingleCoreApplication::instanceId()
{
Q_D(SingleCoreApplication);
return d->instanceNumber;
quint32 SingleCoreApplication::instanceId() {
Q_D(SingleCoreApplication);
return d->instanceNumber;
}
qint64 SingleCoreApplication::primaryPid()
{
Q_D(SingleCoreApplication);
return d->primaryPid();
qint64 SingleCoreApplication::primaryPid() {
Q_D(SingleCoreApplication);
return d->primaryPid();
}
bool SingleCoreApplication::sendMessage( QByteArray message, int timeout )
{
Q_D(SingleCoreApplication);
bool SingleCoreApplication::sendMessage(QByteArray message, int timeout) {
// Nobody to connect to
if( isPrimary() ) return false;
Q_D(SingleCoreApplication);
// Make sure the socket is connected
d->connectToPrimary( timeout, SingleCoreApplicationPrivate::Reconnect );
// Nobody to connect to
if(isPrimary()) return false;
// Make sure the socket is connected
d->connectToPrimary(timeout, SingleCoreApplicationPrivate::Reconnect);
d->socket->write(message);
bool dataWritten = d->socket->waitForBytesWritten(timeout);
d->socket->flush();
return dataWritten;
d->socket->write( message );
bool dataWritten = d->socket->flush();
d->socket->waitForBytesWritten( timeout );
return dataWritten;
}

View File

@@ -20,109 +20,119 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// W A R N I N G !!!
// -----------------
//
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#ifndef SINGLECOREAPPLICATION_H
#define SINGLECOREAPPLICATION_H
#include <QtCore/QtGlobal>
#include <QtGlobal>
#include <QCoreApplication>
#include <QtNetwork/QLocalSocket>
#include <QLocalSocket>
class SingleCoreApplicationPrivate;
/**
* @brief The SingleCoreApplication class handles multipe instances of the same
* @brief The SingleCoreApplication class handles multiple instances of the same
* Application
* @see QCoreApplication
*/
class SingleCoreApplication : public QCoreApplication
{
Q_OBJECT
class SingleCoreApplication : public QCoreApplication {
Q_OBJECT
typedef QCoreApplication app_t;
typedef QCoreApplication app_t;
public:
/**
* @brief Mode of operation of SingleCoreApplication.
* Whether the block should be user-wide or system-wide and whether the
* primary instance should be notified when a secondary instance had been
* started.
* @note Operating system can restrict the shared memory blocks to the same
* user, in which case the User/System modes will have no effect and the
* block will be user wide.
* @enum
*/
enum Mode {
User = 1 << 0,
System = 1 << 1,
SecondaryNotification = 1 << 2,
ExcludeAppVersion = 1 << 3,
ExcludeAppPath = 1 << 4
};
Q_DECLARE_FLAGS(Options, Mode)
/**
* @brief Mode of operation of SingleCoreApplication.
* Whether the block should be user-wide or system-wide and whether the
* primary instance should be notified when a secondary instance had been
* started.
* @note Operating system can restrict the shared memory blocks to the same
* user, in which case the User/System modes will have no effect and the
* block will be user wide.
* @enum
*/
enum Mode {
User = 1 << 0,
System = 1 << 1,
SecondaryNotification = 1 << 2,
ExcludeAppVersion = 1 << 3,
ExcludeAppPath = 1 << 4
};
Q_DECLARE_FLAGS(Options, Mode)
/**
* @brief Intitializes a SingleCoreApplication instance with argc command line
* arguments in argv
* @arg {int &} argc - Number of arguments in argv
* @arg {const char *[]} argv - Supplied command line arguments
* @arg {bool} allowSecondary - Whether to start the instance as secondary
* if there is already a primary instance.
* @arg {Mode} mode - Whether for the SingleCoreApplication block to be applied
* User wide or System wide.
* @arg {int} timeout - Timeout to wait in miliseconds.
* @note argc and argv may be changed as Qt removes arguments that it
* recognizes
* @note Mode::SecondaryNotification only works if set on both the primary
* instance and the secondary instance.
* @note The timeout is just a hint for the maximum time of blocking
* operations. It does not guarantee that the SingleCoreApplication
* initialisation will be completed in given time, though is a good hint.
* Usually 4*timeout would be the worst case (fail) scenario.
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/
explicit SingleCoreApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleCoreApplication();
/**
* @brief Intitializes a SingleCoreApplication instance with argc command line
* arguments in argv
* @arg {int &} argc - Number of arguments in argv
* @arg {const char *[]} argv - Supplied command line arguments
* @arg {bool} allowSecondary - Whether to start the instance as secondary
* if there is already a primary instance.
* @arg {Mode} mode - Whether for the SingleCoreApplication block to be applied
* User wide or System wide.
* @arg {int} timeout - Timeout to wait in milliseconds.
* @note argc and argv may be changed as Qt removes arguments that it
* recognizes
* @note Mode::SecondaryNotification only works if set on both the primary
* instance and the secondary instance.
* @note The timeout is just a hint for the maximum time of blocking
* operations. It does not guarantee that the SingleCoreApplication
* initialisation will be completed in given time, though is a good hint.
* Usually 4*timeout would be the worst case (fail) scenario.
* @see See the corresponding QAPPLICATION_CLASS constructor for reference
*/
explicit SingleCoreApplication( int &argc, char *argv[], bool allowSecondary = false, Options options = Mode::User, int timeout = 1000 );
~SingleCoreApplication();
/**
* @brief Returns if the instance is the primary instance
* @returns {bool}
*/
bool isPrimary();
/**
* @brief Returns if the instance is the primary instance
* @returns {bool}
*/
bool isPrimary();
/**
* @brief Returns if the instance is a secondary instance
* @returns {bool}
*/
bool isSecondary();
/**
* @brief Returns if the instance is a secondary instance
* @returns {bool}
*/
bool isSecondary();
/**
* @brief Returns a unique identifier for the current instance
* @returns {qint32}
*/
quint32 instanceId();
/**
* @brief Returns a unique identifier for the current instance
* @returns {qint32}
*/
quint32 instanceId();
/**
* @brief Returns the process ID (PID) of the primary instance
* @returns {qint64}
*/
qint64 primaryPid();
/**
* @brief Returns the process ID (PID) of the primary instance
* @returns {qint64}
*/
qint64 primaryPid();
/**
* @brief Sends a message to the primary instance. Returns true on success.
* @param {int} timeout - Timeout for connecting
* @returns {bool}
* @note sendMessage() will return false if invoked from the primary
* instance.
*/
bool sendMessage( QByteArray message, int timeout = 100 );
/**
* @brief Sends a message to the primary instance. Returns true on success.
* @param {int} timeout - Timeout for connecting
* @returns {bool}
* @note sendMessage() will return false if invoked from the primary
* instance.
*/
bool sendMessage( QByteArray message, int timeout = 1000 );
Q_SIGNALS:
void instanceStarted();
void receivedMessage( quint32 instanceId, QByteArray message );
signals:
void instanceStarted();
void receivedMessage( quint32 instanceId, QByteArray message );
private:
SingleCoreApplicationPrivate *d_ptr;
Q_DECLARE_PRIVATE(SingleCoreApplication)
SingleCoreApplicationPrivate *d_ptr;
Q_DECLARE_PRIVATE(SingleCoreApplication)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(SingleCoreApplication::Options)

View File

@@ -24,381 +24,386 @@
// W A R N I N G !!!
// -----------------
//
// This file is not part of the SingleCoreApplication API. It is used purely as an
// implementation detail. This header file may change from version to
// version without notice, or may even be removed.
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#include "config.h"
#include <QtGlobal>
#include <cstdlib>
#include <cstddef>
#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtCore/QByteArray>
#include <QtCore/QSemaphore>
#include <QtCore/QDataStream>
#include <QtCore/QStandardPaths>
#include <QtCore/QCryptographicHash>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
#ifdef Q_OS_UNIX
# include <unistd.h>
# include <sys/types.h>
# include <pwd.h>
#endif
#include <QDir>
#include <QByteArray>
#include <QDataStream>
#include <QCryptographicHash>
#include <QLocalServer>
#include <QLocalSocket>
#include "singlecoreapplication.h"
#include "singlecoreapplication_p.h"
#ifdef Q_OS_WIN
#include <windows.h>
#include <lmcons.h>
# include <windows.h>
# include <lmcons.h>
#endif
SingleCoreApplicationPrivate::SingleCoreApplicationPrivate( SingleCoreApplication *q_ptr )
: q_ptr( q_ptr )
{
server = nullptr;
socket = nullptr;
memory = nullptr;
instanceNumber = -1;
}
SingleCoreApplicationPrivate::SingleCoreApplicationPrivate(SingleCoreApplication *q_ptr)
: q_ptr(q_ptr),
memory(nullptr),
socket(nullptr),
server(nullptr),
instanceNumber(-1)
{}
SingleCoreApplicationPrivate::~SingleCoreApplicationPrivate()
{
if( socket != nullptr ) {
socket->close();
delete socket;
}
SingleCoreApplicationPrivate::~SingleCoreApplicationPrivate() {
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
if( server != nullptr ) {
server->close();
delete server;
inst->primary = false;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
memory->unlock();
if (socket != nullptr) {
socket->close();
delete socket;
}
delete memory;
}
void SingleCoreApplicationPrivate::genBlockServerName()
{
QCryptographicHash appData( QCryptographicHash::Sha256 );
appData.addData( "SingleApplication", 17 );
appData.addData( SingleCoreApplication::app_t::applicationName().toUtf8() );
appData.addData( SingleCoreApplication::app_t::organizationName().toUtf8() );
appData.addData( SingleCoreApplication::app_t::organizationDomain().toUtf8() );
if( ! (options & SingleCoreApplication::Mode::ExcludeAppVersion) ) {
appData.addData( SingleCoreApplication::app_t::applicationVersion().toUtf8() );
}
if( ! (options & SingleCoreApplication::Mode::ExcludeAppPath) ) {
#ifdef Q_OS_WIN
appData.addData( SingleCoreApplication::app_t::applicationFilePath().toLower().toUtf8() );
#else
appData.addData( SingleCoreApplication::app_t::applicationFilePath().toUtf8() );
#endif
}
// User level block requires a user specific data in the hash
if( options & SingleCoreApplication::Mode::User ) {
#ifdef Q_OS_WIN
wchar_t username [ UNLEN + 1 ];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if( GetUserNameW( username, &usernameLength ) ) {
appData.addData( QString::fromWCharArray(username).toUtf8() );
} else {
appData.addData( QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).join("").toUtf8() );
}
#endif
#ifdef Q_OS_UNIX
QProcess process;
process.start( "whoami" );
if( process.waitForFinished( 100 ) &&
process.exitCode() == QProcess::NormalExit) {
appData.addData( process.readLine() );
} else {
appData.addData(
QDir(
QStandardPaths::standardLocations( QStandardPaths::HomeLocation ).first()
).absolutePath().toUtf8()
);
}
#endif
}
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with
// server naming requirements.
blockServerName = appData.result().toBase64().replace("/", "_");
}
void SingleCoreApplicationPrivate::initializeMemoryBlock()
{
InstancesInfo* inst = static_cast<InstancesInfo*>( memory->data() );
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
if (server != nullptr) {
server->close();
delete server;
inst->primary = false;
inst->secondary = 0;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
memory->unlock();
delete memory;
}
void SingleCoreApplicationPrivate::startPrimary()
{
Q_Q(SingleCoreApplication);
void SingleCoreApplicationPrivate::genBlockServerName() {
// Successful creation means that no main process exists
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer( blockServerName );
server = new QLocalServer();
QCryptographicHash appData(QCryptographicHash::Sha256);
appData.addData("SingleApplication", 17);
appData.addData(SingleCoreApplication::app_t::applicationName().toUtf8());
appData.addData(SingleCoreApplication::app_t::organizationName().toUtf8());
appData.addData(SingleCoreApplication::app_t::organizationDomain().toUtf8());
// Restrict access to the socket according to the
// SingleCoreApplication::Mode::User flag on User level or no restrictions
if( options & SingleCoreApplication::Mode::User ) {
server->setSocketOptions( QLocalServer::UserAccessOption );
} else {
server->setSocketOptions( QLocalServer::WorldAccessOption );
if (!(options & SingleCoreApplication::Mode::ExcludeAppVersion)) {
appData.addData(SingleCoreApplication::app_t::applicationVersion().toUtf8());
}
if (!(options & SingleCoreApplication::Mode::ExcludeAppPath)) {
#ifdef Q_OS_WIN
appData.addData(SingleCoreApplication::app_t::applicationFilePath().toLower().toUtf8());
#else
appData.addData(SingleCoreApplication::app_t::applicationFilePath().toUtf8());
#endif
}
// User level block requires a user specific data in the hash
if (options & SingleCoreApplication::Mode::User) {
#ifdef Q_OS_UNIX
QByteArray username;
#if defined(HAVE_GETEUID) && defined(HAVE_GETPWUID)
uid_t uid = geteuid();
if (uid != -1) {
struct passwd *pw = getpwuid(uid);
if (pw) {
username = pw->pw_name;
}
}
#endif
if (username.isEmpty()) username = qgetenv("USER");
appData.addData(username);
#endif
#ifdef Q_OS_WIN
wchar_t username [ UNLEN + 1 ];
// Specifies size of the buffer on input
DWORD usernameLength = UNLEN + 1;
if (GetUserNameW(username, &usernameLength)) {
appData.addData(QString::fromWCharArray(username).toUtf8());
}
else {
appData.addData(qgetenv("USERNAME"));
}
#endif
}
server->listen( blockServerName );
QObject::connect(
server,
&QLocalServer::newConnection,
this,
&SingleCoreApplicationPrivate::slotConnectionEstablished
);
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
blockServerName = appData.result().toBase64().replace("/", "_");
// Reset the number of connections
InstancesInfo* inst = static_cast <InstancesInfo*>( memory->data() );
inst->primary = true;
inst->primaryPid = q->applicationPid();
inst->checksum = blockChecksum();
instanceNumber = 0;
}
void SingleCoreApplicationPrivate::startSecondary()
{
void SingleCoreApplicationPrivate::initializeMemoryBlock() {
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
inst->primary = false;
inst->secondary = 0;
inst->primaryPid = -1;
inst->checksum = blockChecksum();
}
void SingleCoreApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
{
// Connect to the Local Server of the Primary Instance if not already
// connected.
if( socket == nullptr ) {
socket = new QLocalSocket();
}
void SingleCoreApplicationPrivate::startPrimary() {
// If already connected - we are done;
if( socket->state() == QLocalSocket::ConnectedState )
return;
Q_Q(SingleCoreApplication);
// If not connect
if( socket->state() == QLocalSocket::UnconnectedState ||
socket->state() == QLocalSocket::ClosingState ) {
socket->connectToServer( blockServerName );
}
// Successful creation means that no main process exists
// So we start a QLocalServer to listen for connections
QLocalServer::removeServer(blockServerName);
server = new QLocalServer();
// Wait for being connected
if( socket->state() == QLocalSocket::ConnectingState ) {
socket->waitForConnected( msecs );
}
// Restrict access to the socket according to the
// SingleCoreApplication::Mode::User flag on User level or no restrictions
if (options & SingleCoreApplication::Mode::User) {
server->setSocketOptions(QLocalServer::UserAccessOption);
}
else {
server->setSocketOptions(QLocalServer::WorldAccessOption);
}
// Initialisation message according to the SingleCoreApplication protocol
if( socket->state() == QLocalSocket::ConnectedState ) {
// Notify the parent that a new instance had been started;
QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
server->listen(blockServerName);
QObject::connect(server, &QLocalServer::newConnection, this, &SingleCoreApplicationPrivate::slotConnectionEstablished);
// Reset the number of connections
InstancesInfo* inst = static_cast <InstancesInfo*>(memory->data());
inst->primary = true;
inst->primaryPid = q->applicationPid();
inst->checksum = blockChecksum();
instanceNumber = 0;
}
void SingleCoreApplicationPrivate::startSecondary() {}
void SingleCoreApplicationPrivate::connectToPrimary(int msecs, ConnectionType connectionType) {
// Connect to the Local Server of the Primary Instance if not already connected.
if (socket == nullptr) {
socket = new QLocalSocket();
}
// If already connected - we are done;
if (socket->state() == QLocalSocket::ConnectedState)
return;
// If not connect
if (socket->state() == QLocalSocket::UnconnectedState ||
socket->state() == QLocalSocket::ClosingState) {
socket->connectToServer(blockServerName);
}
// Wait for being connected
if (socket->state() == QLocalSocket::ConnectingState) {
socket->waitForConnected(msecs);
}
// Initialisation message according to the SingleCoreApplication protocol
if (socket->state() == QLocalSocket::ConnectedState) {
// Notify the parent that a new instance had been started;
QByteArray initMsg;
QDataStream writeStream(&initMsg, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
writeStream.setVersion(QDataStream::Qt_5_6);
writeStream.setVersion(QDataStream::Qt_5_6);
#endif
writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType);
writeStream << instanceNumber;
quint16 checksum = qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length()));
writeStream << checksum;
writeStream << blockServerName.toLatin1();
writeStream << static_cast<quint8>(connectionType);
writeStream << instanceNumber;
quint16 checksum = qChecksum(initMsg.constData(), static_cast<quint32>(initMsg.length()));
writeStream << checksum;
// The header indicates the message length that follows
QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly);
// The header indicates the message length that follows
QByteArray header;
QDataStream headerStream(&header, QIODevice::WriteOnly);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion(QDataStream::Qt_5_6);
headerStream.setVersion(QDataStream::Qt_5_6);
#endif
headerStream << static_cast <quint64>( initMsg.length() );
headerStream << static_cast <quint64>(initMsg.length());
socket->write(header);
socket->write(initMsg);
socket->flush();
socket->waitForBytesWritten(msecs);
}
socket->write( header );
socket->write( initMsg );
socket->flush();
socket->waitForBytesWritten( msecs );
}
}
quint16 SingleCoreApplicationPrivate::blockChecksum()
{
return qChecksum(
static_cast <const char *>( memory->data() ),
offsetof( InstancesInfo, checksum )
);
quint16 SingleCoreApplicationPrivate::blockChecksum() {
return qChecksum(static_cast <const char*> (memory->data()), offsetof(InstancesInfo, checksum));
}
qint64 SingleCoreApplicationPrivate::primaryPid()
{
qint64 pid;
qint64 SingleCoreApplicationPrivate::primaryPid() {
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>( memory->data() );
pid = inst->primaryPid;
memory->unlock();
qint64 pid;
memory->lock();
InstancesInfo* inst = static_cast<InstancesInfo*>(memory->data());
pid = inst->primaryPid;
memory->unlock();
return pid;
return pid;
}
/**
* @brief Executed when a connection has been made to the LocalServer
*/
void SingleCoreApplicationPrivate::slotConnectionEstablished()
{
QLocalSocket *nextConnSocket = server->nextPendingConnection();
connectionMap.insert(nextConnSocket, ConnectionInfo());
void SingleCoreApplicationPrivate::slotConnectionEstablished() {
QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
Q_EMIT this->slotClientConnectionClosed( nextConnSocket, info.instanceId );
}
);
QLocalSocket *nextConnSocket = server->nextPendingConnection();
connectionMap.insert(nextConnSocket, ConnectionInfo());
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
[nextConnSocket, this](){
connectionMap.remove(nextConnSocket);
nextConnSocket->deleteLater();
}
);
QObject::connect(nextConnSocket, &QLocalSocket::aboutToClose,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
}
);
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
[nextConnSocket, this](){
connectionMap.remove(nextConnSocket);
nextConnSocket->deleteLater();
}
);
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
switch(info.stage) {
case StageHeader:
readInitMessageHeader(nextConnSocket);
break;
case StageBody:
readInitMessageBody(nextConnSocket);
break;
case StageConnected:
Q_EMIT this->slotDataAvailable(nextConnSocket, info.instanceId);
break;
default:
break;
};
}
);
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
[nextConnSocket, this]() {
auto &info = connectionMap[nextConnSocket];
switch(info.stage) {
case StageHeader:
readInitMessageHeader(nextConnSocket);
break;
case StageBody:
readInitMessageBody(nextConnSocket);
break;
case StageConnected:
Q_EMIT this->slotDataAvailable( nextConnSocket, info.instanceId );
break;
default:
break;
};
}
);
}
void SingleCoreApplicationPrivate::readInitMessageHeader( QLocalSocket *sock )
{
if (!connectionMap.contains( sock )) {
return;
}
void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
if( sock->bytesAvailable() < ( qint64 )sizeof( quint64 ) ) {
return;
}
if (!connectionMap.contains(sock)) {
return;
}
QDataStream headerStream( sock );
if (sock->bytesAvailable() < (qint64)sizeof(quint64)) {
return;
}
QDataStream headerStream(sock);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
headerStream.setVersion( QDataStream::Qt_5_6 );
headerStream.setVersion(QDataStream::Qt_5_6);
#endif
// Read the header to know the message length
quint64 msgLen = 0;
headerStream >> msgLen;
ConnectionInfo &info = connectionMap[sock];
info.stage = StageBody;
info.msgLen = msgLen;
// Read the header to know the message length
quint64 msgLen = 0;
headerStream >> msgLen;
ConnectionInfo &info = connectionMap[sock];
info.stage = StageBody;
info.msgLen = msgLen;
if (sock->bytesAvailable() >= (qint64) msgLen) {
readInitMessageBody(sock);
}
if ( sock->bytesAvailable() >= (qint64) msgLen ) {
readInitMessageBody( sock );
}
}
void SingleCoreApplicationPrivate::readInitMessageBody( QLocalSocket *sock )
{
Q_Q(SingleCoreApplication);
void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
if (!connectionMap.contains( sock )) {
return;
}
Q_Q(SingleCoreApplication);
ConnectionInfo &info = connectionMap[sock];
if( sock->bytesAvailable() < ( qint64 )info.msgLen ) {
return;
}
if (!connectionMap.contains(sock)) {
return;
}
// Read the message body
QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes);
ConnectionInfo &info = connectionMap[sock];
if (sock->bytesAvailable() < (qint64)info.msgLen) {
return;
}
// Read the message body
QByteArray msgBytes = sock->read(info.msgLen);
QDataStream readStream(msgBytes);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
readStream.setVersion( QDataStream::Qt_5_6 );
readStream.setVersion(QDataStream::Qt_5_6);
#endif
// server name
QByteArray latin1Name;
readStream >> latin1Name;
// server name
QByteArray latin1Name;
readStream >> latin1Name;
// connection type
ConnectionType connectionType = InvalidConnection;
quint8 connTypeVal = InvalidConnection;
readStream >> connTypeVal;
connectionType = static_cast <ConnectionType>( connTypeVal );
// connection type
ConnectionType connectionType = InvalidConnection;
quint8 connTypeVal = InvalidConnection;
readStream >> connTypeVal;
connectionType = static_cast <ConnectionType>(connTypeVal);
// instance id
quint32 instanceId = 0;
readStream >> instanceId;
// instance id
quint32 instanceId = 0;
readStream >> instanceId;
// checksum
quint16 msgChecksum = 0;
readStream >> msgChecksum;
// checksum
quint16 msgChecksum = 0;
readStream >> msgChecksum;
const quint16 actualChecksum = qChecksum( msgBytes.constData(), static_cast<quint32>( msgBytes.length() - sizeof( quint16 ) ) );
const quint16 actualChecksum = qChecksum(msgBytes.constData(), static_cast<quint32>(msgBytes.length() - sizeof(quint16)));
bool isValid = readStream.status() == QDataStream::Ok &&
QLatin1String(latin1Name) == blockServerName &&
msgChecksum == actualChecksum;
bool isValid = readStream.status() == QDataStream::Ok && QLatin1String(latin1Name) == blockServerName && msgChecksum == actualChecksum;
if( !isValid ) {
sock->close();
return;
}
if (!isValid) {
sock->close();
return;
}
info.instanceId = instanceId;
info.stage = StageConnected;
info.instanceId = instanceId;
info.stage = StageConnected;
if( connectionType == NewInstance ||
( connectionType == SecondaryInstance &&
options & SingleCoreApplication::Mode::SecondaryNotification ) )
{
Q_EMIT q->instanceStarted();
}
if (connectionType == NewInstance || (connectionType == SecondaryInstance && options & SingleCoreApplication::Mode::SecondaryNotification)) {
Q_EMIT q->instanceStarted();
}
if (sock->bytesAvailable() > 0) {
Q_EMIT this->slotDataAvailable(sock, instanceId);
}
if (sock->bytesAvailable() > 0) {
Q_EMIT this->slotDataAvailable( sock, instanceId );
}
}
void SingleCoreApplicationPrivate::slotDataAvailable( QLocalSocket *dataSocket, quint32 instanceId )
{
Q_Q(SingleCoreApplication);
Q_EMIT q->receivedMessage( instanceId, dataSocket->readAll() );
void SingleCoreApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, quint32 instanceId) {
Q_Q(SingleCoreApplication);
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
}
void SingleCoreApplicationPrivate::slotClientConnectionClosed( QLocalSocket *closedSocket, quint32 instanceId )
{
if( closedSocket->bytesAvailable() > 0 )
Q_EMIT slotDataAvailable( closedSocket, instanceId );
void SingleCoreApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, quint32 instanceId) {
if (closedSocket->bytesAvailable() > 0)
Q_EMIT slotDataAvailable(closedSocket, instanceId);
}

View File

@@ -24,76 +24,80 @@
// W A R N I N G !!!
// -----------------
//
// This file is not part of the SingleCoreApplication API. It is used purely as an
// implementation detail. This header file may change from version to
// version without notice, or may even be removed.
// This is a modified version of SingleApplication,
// The original version is at:
//
// https://github.com/itay-grudev/SingleApplication
//
//
#ifndef SINGLECOREAPPLICATION_P_H
#define SINGLECOREAPPLICATION_P_H
#include <QtCore/QSharedMemory>
#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>
#include <QtGlobal>
#include <QLocalSocket>
#include <QLocalServer>
#include <QSharedMemory>
#include <QMap>
#include "singlecoreapplication.h"
struct InstancesInfo {
bool primary;
quint32 secondary;
qint64 primaryPid;
quint16 checksum;
bool primary;
quint32 secondary;
qint64 primaryPid;
quint16 checksum;
};
struct ConnectionInfo {
explicit ConnectionInfo() :
msgLen(0), instanceId(0), stage(0) {}
qint64 msgLen;
quint32 instanceId;
quint8 stage;
explicit ConnectionInfo() : msgLen(0), instanceId(0), stage(0) {}
qint64 msgLen;
quint32 instanceId;
quint8 stage;
};
class SingleCoreApplicationPrivate : public QObject {
Q_OBJECT
public:
enum ConnectionType : quint8 {
InvalidConnection = 0,
NewInstance = 1,
SecondaryInstance = 2,
Reconnect = 3
};
enum ConnectionStage : quint8 {
StageHeader = 0,
StageBody = 1,
StageConnected = 2,
};
Q_DECLARE_PUBLIC(SingleCoreApplication)
Q_OBJECT
public:
enum ConnectionType : quint8 {
InvalidConnection = 0,
NewInstance = 1,
SecondaryInstance = 2,
Reconnect = 3
};
enum ConnectionStage : quint8 {
StageHeader = 0,
StageBody = 1,
StageConnected = 2,
};
Q_DECLARE_PUBLIC(SingleCoreApplication)
SingleCoreApplicationPrivate( SingleCoreApplication *q_ptr );
~SingleCoreApplicationPrivate();
SingleCoreApplicationPrivate( SingleCoreApplication *q_ptr );
~SingleCoreApplicationPrivate();
void genBlockServerName();
void initializeMemoryBlock();
void startPrimary();
void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType );
quint16 blockChecksum();
qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
void genBlockServerName();
void initializeMemoryBlock();
void startPrimary();
void startSecondary();
void connectToPrimary(int msecs, ConnectionType connectionType );
quint16 blockChecksum();
qint64 primaryPid();
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
SingleCoreApplication *q_ptr;
QSharedMemory *memory;
QLocalSocket *socket;
QLocalServer *server;
quint32 instanceNumber;
QString blockServerName;
SingleCoreApplication::Options options;
QMap<QLocalSocket*, ConnectionInfo> connectionMap;
SingleCoreApplication *q_ptr;
QSharedMemory *memory;
QLocalSocket *socket;
QLocalServer *server;
quint32 instanceNumber;
QString blockServerName;
SingleCoreApplication::Options options;
QMap<QLocalSocket*, ConnectionInfo> connectionMap;
public Q_SLOTS:
void slotConnectionEstablished();
void slotDataAvailable( QLocalSocket*, quint32 );
void slotClientConnectionClosed( QLocalSocket*, quint32 );
public slots:
void slotConnectionEstablished();
void slotDataAvailable(QLocalSocket*, quint32);
void slotClientConnectionClosed(QLocalSocket*, quint32);
};
#endif // SINGLECOREAPPLICATION_P_H
#endif // SINGLECOREAPPLICATION_P_H

View File

@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -fpermissive -Wall -Woverloaded-virtual -Wno-sign-compare -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-delete-non-virtual-dtor")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11 -U__STRICT_ANSI__ -fpermissive -Wall -Woverloaded-virtual -Wno-sign-compare -Wno-delete-non-virtual-dtor")
set(TAGLIB_SOVERSION_CURRENT 17)
set(TAGLIB_SOVERSION_REVISION 0)
@@ -93,6 +93,7 @@ set(tag_HDRS
mpeg/xingheader.h
mpeg/id3v1/id3v1tag.h
mpeg/id3v1/id3v1genres.h
mpeg/id3v2/id3v2.h
mpeg/id3v2/id3v2extendedheader.h
mpeg/id3v2/id3v2frame.h
mpeg/id3v2/id3v2header.h

View File

@@ -57,12 +57,12 @@ namespace TagLib {
namespace APE {
//! An implementation of Strawberry_TagLib::TagLib::File with APE specific methods
//! An implementation of TagLib::File with APE specific methods
/*!
* This implements and provides an interface for APE files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to APE files.
*/

View File

@@ -56,7 +56,7 @@ namespace TagLib {
*
* \deprecated
*/
Properties(File *file, ReadStyle style = Average);
TAGLIB_DEPRECATED Properties(File *file, ReadStyle style = Average);
/*!
* Create an instance of APE::Properties with the data read from the
@@ -77,7 +77,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -81,7 +81,7 @@ namespace TagLib
* only one may be of type 1 and only one may be of type 2.
*
* The specification also states that the description of the picture can be no longer than 64 characters, but can be empty.
* WM/Picture attributes added with Strawberry_TagLib::TagLib::ASF are not automatically validated to conform to ID3 specifications.
* WM/Picture attributes added with TagLib::ASF are not automatically validated to conform to ID3 specifications.
* You must add code in your application to perform validations if you want to maintain complete compatibility with ID3.
*/
Attribute(const Picture &value);

View File

@@ -40,8 +40,8 @@ namespace TagLib {
/*!
* This implements and provides an interface for ASF files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to ASF files.
*/
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File
@@ -80,7 +80,7 @@ namespace TagLib {
* Returns a pointer to the ASF tag of the file.
*
* ASF::Tag implements the tag interface, so this serves as the
* reimplementation of Strawberry_TagLib::TagLib::File::tag().
* reimplementation of TagLib::File::tag().
*
* \note The Tag <b>is still</b> owned by the ASF::File and should not be
* deleted by the user. It will be deleted when the file (object) is

View File

@@ -161,6 +161,7 @@ namespace TagLib {
* Returns a reference to the item list map. This is an AttributeListMap of
* all of the items in the tag.
*/
// BIC: return by value
const AttributeListMap &attributeListMap() const;
/*!

View File

@@ -36,7 +36,7 @@ namespace TagLib {
/*!
* The values here are common to most audio formats. For more specific, codec
* dependent values, please see see the subclasses APIs. This is meant to
* compliment the Strawberry_TagLib::TagLib::File and Strawberry_TagLib::TagLib::Tag APIs in providing a simple
* compliment the TagLib::File and TagLib::Tag APIs in providing a simple
* interface that is sufficient for most applications.
*/

View File

@@ -33,18 +33,45 @@
#include "tagunion.h"
#include "dsdifffile.h"
using namespace Strawberry_TagLib::TagLib;
#include <array>
struct Chunk64
{
ByteVector name;
unsigned long long offset;
unsigned long long size;
char padding;
};
using namespace Strawberry_TagLib::TagLib;
namespace
{
struct Chunk64
{
ByteVector name;
unsigned long long offset;
unsigned long long size;
char padding;
};
typedef std::vector<Chunk64> ChunkList;
int chunkIndex(const ChunkList &chunks, const ByteVector &id)
{
for(int i = 0; i < chunks.size(); i++) {
if(chunks[i].name == id)
return i;
}
return -1;
}
bool isValidChunkID(const ByteVector &name)
{
if(name.size() != 4)
return false;
for(int i = 0; i < 4; i++) {
if(name[i] < 32 || name[i] > 127)
return false;
}
return true;
}
enum {
ID3v2Index = 0,
DIINIndex = 1
@@ -59,14 +86,14 @@ class DSDIFF::File::FilePrivate
{
public:
FilePrivate() :
endianness(BigEndian),
size(0),
isID3InPropChunk(false),
duplicateID3V2chunkIndex(-1),
properties(0),
id3v2TagChunkID("ID3 "),
hasID3v2(false),
hasDiin(false)
endianness(BigEndian),
size(0),
isID3InPropChunk(false),
duplicateID3V2chunkIndex(-1),
properties(0),
id3v2TagChunkID("ID3 "),
hasID3v2(false),
hasDiin(false)
{
childChunkIndex[ID3v2Index] = -1;
childChunkIndex[DIINIndex] = -1;
@@ -81,12 +108,18 @@ public:
ByteVector type;
unsigned long long size;
ByteVector format;
std::vector<Chunk64> chunks;
std::vector<Chunk64> childChunks[2];
int childChunkIndex[2];
bool isID3InPropChunk; // Two possibilities can be found: ID3V2 chunk inside PROP chunk or at root level
int duplicateID3V2chunkIndex; // 2 ID3 chunks are present. This is then the index of the one in
// PROP chunk that will be removed upon next save to remove duplicates.
ChunkList chunks;
std::array<ChunkList, 2> childChunks;
std::array<int, 2> childChunkIndex;
/*
* Two possibilities can be found: ID3V2 chunk inside PROP chunk or at root level
*/
bool isID3InPropChunk;
/*
* ID3 chunks are present. This is then the index of the one in PROP chunk that
* will be removed upon next save to remove duplicates.
*/
int duplicateID3V2chunkIndex;
Properties *properties;
@@ -142,9 +175,9 @@ Strawberry_TagLib::TagLib::Tag *DSDIFF::File::tag() const
return &d->tag;
}
ID3v2::Tag *DSDIFF::File::ID3v2Tag() const
ID3v2::Tag *DSDIFF::File::ID3v2Tag(bool create) const
{
return d->tag.access<ID3v2::Tag>(ID3v2Index, false);
return d->tag.access<ID3v2::Tag>(ID3v2Index, create);
}
bool DSDIFF::File::hasID3v2Tag() const
@@ -152,9 +185,9 @@ bool DSDIFF::File::hasID3v2Tag() const
return d->hasID3v2;
}
DSDIFF::DIIN::Tag *DSDIFF::File::DIINTag() const
DSDIFF::DIIN::Tag *DSDIFF::File::DIINTag(bool create) const
{
return d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false);
return d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, create);
}
bool DSDIFF::File::hasDIINTag() const
@@ -190,6 +223,11 @@ DSDIFF::Properties *DSDIFF::File::audioProperties() const
}
bool DSDIFF::File::save()
{
return save(AllTags);
}
bool DSDIFF::File::save(TagTypes tags, StripTags strip, ID3v2::Version version)
{
if(readOnly()) {
debug("DSDIFF::File::save() -- File is read only.");
@@ -201,36 +239,44 @@ bool DSDIFF::File::save()
return false;
}
//if(strip == StripOthers || strip == StripAll)
//File::strip(static_cast<TagTypes>(AllTags & ~tags));
// First: save ID3V2 chunk
ID3v2::Tag *id3v2Tag = d->tag.access<ID3v2::Tag>(ID3v2Index, false);
if(d->isID3InPropChunk) {
if(id3v2Tag != NULL && !id3v2Tag->isEmpty()) {
setChildChunkData(d->id3v2TagChunkID, id3v2Tag->render(), PROPChunk);
d->hasID3v2 = true;
if(tags & ID3v2 && id3v2Tag) {
if(d->isID3InPropChunk) {
if(id3v2Tag && !id3v2Tag->isEmpty()) {
setChildChunkData(d->id3v2TagChunkID, id3v2Tag->render(version), PROPChunk);
d->hasID3v2 = true;
}
else {
// Empty tag: remove it
setChildChunkData(d->id3v2TagChunkID, ByteVector(), PROPChunk);
d->hasID3v2 = false;
}
}
else {
// Empty tag: remove it
setChildChunkData(d->id3v2TagChunkID, ByteVector(), PROPChunk);
d->hasID3v2 = false;
}
}
else {
if(id3v2Tag != NULL && !id3v2Tag->isEmpty()) {
setRootChunkData(d->id3v2TagChunkID, id3v2Tag->render());
d->hasID3v2 = true;
}
else {
// Empty tag: remove it
setRootChunkData(d->id3v2TagChunkID, ByteVector());
d->hasID3v2 = false;
if(id3v2Tag && !id3v2Tag->isEmpty()) {
setRootChunkData(d->id3v2TagChunkID, id3v2Tag->render(version));
d->hasID3v2 = true;
}
else {
// Empty tag: remove it
setRootChunkData(d->id3v2TagChunkID, ByteVector());
d->hasID3v2 = false;
}
}
}
// Second: save the DIIN chunk
if(d->hasDiin) {
DSDIFF::DIIN::Tag *diinTag = d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false);
if(!diinTag->title().isNull() && !diinTag->title().isEmpty()) {
DSDIFF::DIIN::Tag *diinTag = d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, false);
if(tags & DIIN && diinTag) {
if(!diinTag->title().isEmpty()) {
ByteVector diinTitle;
diinTitle.append(ByteVector::fromUInt(diinTag->title().size(), d->endianness == BigEndian));
diinTitle.append(ByteVector::fromCString(diinTag->title().toCString()));
@@ -239,7 +285,7 @@ bool DSDIFF::File::save()
else
setChildChunkData("DITI", ByteVector(), DIINChunk);
if(!diinTag->artist().isNull() && !diinTag->artist().isEmpty()) {
if(!diinTag->artist().isEmpty()) {
ByteVector diinArtist;
diinArtist.append(ByteVector::fromUInt(diinTag->artist().size(), d->endianness == BigEndian));
diinArtist.append(ByteVector::fromCString(diinTag->artist().toCString()));
@@ -258,46 +304,80 @@ bool DSDIFF::File::save()
return true;
}
void DSDIFF::File::strip(TagTypes tags)
{
if(tags & ID3v2) {
removeRootChunk("ID3 ");
removeRootChunk("id3 ");
d->hasID3v2 = false;
d->tag.set(ID3v2Index, new ID3v2::Tag);
/// TODO: needs to also account for ID3v2 tags under the PROP chunk
}
if(tags & DIIN) {
removeRootChunk("DITI");
removeRootChunk("DIAR");
d->hasDiin = false;
d->tag.set(DIINIndex, new DIIN::Tag);
}
}
////////////////////////////////////////////////////////////////////////////////
// private members
////////////////////////////////////////////////////////////////////////////////
void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data)
void DSDIFF::File::removeRootChunk(unsigned int i)
{
if(data.isNull() || data.isEmpty()) {
// Null data: remove chunk
// Update global size
unsigned long long removedChunkTotalSize = d->chunks[i].size + d->chunks[i].padding + 12;
d->size -= removedChunkTotalSize;
unsigned long long chunkSize = d->chunks[i].size + d->chunks[i].padding + 12;
d->size -= chunkSize;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
removeBlock(d->chunks[i].offset - 12, removedChunkTotalSize);
removeBlock(d->chunks[i].offset - 12, chunkSize);
// Update the internal offsets
for(unsigned long r = i + 1; r < d->chunks.size(); r++)
d->chunks[r].offset = d->chunks[r - 1].offset + 12
+ d->chunks[r - 1].size + d->chunks[r - 1].padding;
d->chunks.erase(d->chunks.begin() + i);
}
void DSDIFF::File::removeRootChunk(const ByteVector &id)
{
int i = chunkIndex(d->chunks, id);
if(i >= 0)
removeRootChunk(i);
}
void DSDIFF::File::setRootChunkData(unsigned int i, const ByteVector &data)
{
if(data.isEmpty()) {
removeRootChunk(i);
return;
}
else {
// Non null data: update chunk
// First we update the global size
d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding);
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// Now update the specific chunk
writeChunk(d->chunks[i].name,
data,
d->chunks[i].offset - 12,
d->chunks[i].size + d->chunks[i].padding + 12);
// Non null data: update chunk
// First we update the global size
d->chunks[i].size = data.size();
d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0;
d->size += ((data.size() + 1) & ~1) - (d->chunks[i].size + d->chunks[i].padding);
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// Finally update the internal offsets
updateRootChunksStructure(i + 1);
}
// Now update the specific chunk
writeChunk(d->chunks[i].name,
data,
d->chunks[i].offset - 12,
d->chunks[i].size + d->chunks[i].padding + 12);
d->chunks[i].size = data.size();
d->chunks[i].padding = (data.size() & 0x01) ? 1 : 0;
// Finally update the internal offsets
updateRootChunksStructure(i + 1);
}
void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &data)
@@ -307,15 +387,15 @@ void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &da
return;
}
for(unsigned int i = 0; i < d->chunks.size(); i++) {
if(d->chunks[i].name == name) {
setRootChunkData(i, data);
return;
}
int i = chunkIndex(d->chunks, name);
if(i >= 0) {
setRootChunkData(i, data);
return;
}
// Couldn't find an existing chunk, so let's create a new one.
unsigned int i = d->chunks.size() - 1;
i = d->chunks.size() - 1;
unsigned long offset = d->chunks[i].offset + d->chunks[i].size + d->chunks[i].padding;
// First we update the global size
@@ -338,28 +418,29 @@ void DSDIFF::File::setRootChunkData(const ByteVector &name, const ByteVector &da
d->chunks.push_back(chunk);
}
void DSDIFF::File::setChildChunkData(unsigned int i,
const ByteVector &data,
unsigned int childChunkNum)
void DSDIFF::File::removeChildChunk(unsigned int i, unsigned int childChunkNum)
{
std::vector<Chunk64> &childChunks = d->childChunks[childChunkNum];
ChunkList &childChunks = d->childChunks[childChunkNum];
if(data.isNull() || data.isEmpty()) {
// Null data: remove chunk
// Update global size
unsigned long long removedChunkTotalSize = childChunks[i].size + childChunks[i].padding + 12;
d->size -= removedChunkTotalSize;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// Update child chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size -= removedChunkTotalSize;
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size,
d->endianness == BigEndian),
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Remove the chunk
removeBlock(childChunks[i].offset - 12, removedChunkTotalSize);
// Update the internal offsets
// For child chunks
if((i + 1) < childChunks.size()) {
childChunks[i + 1].offset = childChunks[i].offset;
i++;
@@ -369,49 +450,65 @@ void DSDIFF::File::setChildChunkData(unsigned int i,
}
// And for root chunks
for(i = d->childChunkIndex[childChunkNum] + 1; i < d->chunks.size(); i++)
d->chunks[i].offset = d->chunks[i - 1].offset + 12
+ d->chunks[i - 1].size + d->chunks[i - 1].padding;
childChunks.erase(childChunks.begin() + i);
}
void DSDIFF::File::setChildChunkData(unsigned int i,
const ByteVector &data,
unsigned int childChunkNum)
{
ChunkList &childChunks = d->childChunks[childChunkNum];
if(data.isEmpty()) {
removeChildChunk(i, childChunkNum);
return;
}
else {
// Non null data: update chunk
// First we update the global size
d->size += ((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// And the PROP chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size += ((data.size() + 1) & ~1)
- (childChunks[i].size + childChunks[i].padding);
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size,
d->endianness == BigEndian),
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Now update the specific chunk
writeChunk(childChunks[i].name,
data,
childChunks[i].offset - 12,
childChunks[i].size + childChunks[i].padding + 12);
// Non null data: update chunk
// First we update the global size
childChunks[i].size = data.size();
childChunks[i].padding = (data.size() & 0x01) ? 1 : 0;
d->size += ((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
// Now update the internal offsets
// For child Chunks
for(i++; i < childChunks.size(); i++)
childChunks[i].offset = childChunks[i - 1].offset + 12
+ childChunks[i - 1].size + childChunks[i - 1].padding;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// And for root chunks
updateRootChunksStructure(d->childChunkIndex[childChunkNum] + 1);
}
// And the PROP chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size +=
((data.size() + 1) & ~1) - (childChunks[i].size + childChunks[i].padding);
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size,
d->endianness == BigEndian),
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Now update the specific chunk
writeChunk(childChunks[i].name,
data,
childChunks[i].offset - 12,
childChunks[i].size + childChunks[i].padding + 12);
childChunks[i].size = data.size();
childChunks[i].padding = (data.size() & 0x01) ? 1 : 0;
// Now update the internal offsets
// For child Chunks
for(i++; i < childChunks.size(); i++)
childChunks[i].offset = childChunks[i - 1].offset + 12
+ childChunks[i - 1].size + childChunks[i - 1].padding;
// And for root chunks
updateRootChunksStructure(d->childChunkIndex[childChunkNum] + 1);
}
void DSDIFF::File::setChildChunkData(const ByteVector &name,
const ByteVector &data,
unsigned int childChunkNum)
{
std::vector<Chunk64> &childChunks = d->childChunks[childChunkNum];
ChunkList &childChunks = d->childChunks[childChunkNum];
if(childChunks.size() == 0) {
debug("DSDIFF::File::setPropChunkData - No valid chunks found.");
@@ -426,17 +523,22 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
}
// Do not attempt to remove a non existing chunk
if(data.isNull() || data.isEmpty())
if(data.isEmpty())
return;
// Couldn't find an existing chunk, so let's create a new one.
unsigned int i = childChunks.size() - 1;
unsigned long offset = childChunks[i].offset + childChunks[i].size + childChunks[i].padding;
// First we update the global size
d->size += (offset & 1) + ((data.size() + 1) & ~1) + 12;
insert(ByteVector::fromLongLong(d->size, d->endianness == BigEndian), 4, 8);
// And the child chunk size
d->chunks[d->childChunkIndex[childChunkNum]].size += (offset & 1)
+ ((data.size() + 1) & ~1) + 12;
insert(ByteVector::fromLongLong(d->chunks[d->childChunkIndex[childChunkNum]].size,
@@ -444,6 +546,7 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
d->chunks[d->childChunkIndex[childChunkNum]].offset - 8, 8);
// Now add the chunk to the file
unsigned long long nextRootChunkIdx = length();
if((d->childChunkIndex[childChunkNum] + 1) < static_cast<int>(d->chunks.size()))
nextRootChunkIdx = d->chunks[d->childChunkIndex[childChunkNum] + 1].offset - 12;
@@ -453,6 +556,7 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
(offset & 1) ? 1 : 0);
// For root chunks
updateRootChunksStructure(d->childChunkIndex[childChunkNum] + 1);
Chunk64 chunk;
@@ -464,19 +568,6 @@ void DSDIFF::File::setChildChunkData(const ByteVector &name,
childChunks.push_back(chunk);
}
static bool isValidChunkID(const ByteVector &name)
{
if(name.size() != 4)
return false;
for(int i = 0; i < 4; i++) {
if(name[i] < 32 || name[i] > 127)
return false;
}
return true;
}
void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk)
{
for(unsigned int i = startingChunk; i < d->chunks.size(); i++)
@@ -484,17 +575,19 @@ void DSDIFF::File::updateRootChunksStructure(unsigned int startingChunk)
+ d->chunks[i - 1].size + d->chunks[i - 1].padding;
// Update childchunks structure as well
if(d->childChunkIndex[PROPChunk] >= static_cast<int>(startingChunk)) {
std::vector<Chunk64> &childChunksToUpdate = d->childChunks[PROPChunk];
ChunkList &childChunksToUpdate = d->childChunks[PROPChunk];
if(childChunksToUpdate.size() > 0) {
childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[PROPChunk]].offset + 12;
for(unsigned int i = 1; i < childChunksToUpdate.size(); i++)
childChunksToUpdate[i].offset = childChunksToUpdate[i - 1].offset + 12
+ childChunksToUpdate[i - 1].size + childChunksToUpdate[i - 1].padding;
}
}
if(d->childChunkIndex[DIINChunk] >= static_cast<int>(startingChunk)) {
std::vector<Chunk64> &childChunksToUpdate = d->childChunks[DIINChunk];
ChunkList &childChunksToUpdate = d->childChunks[DIINChunk];
if(childChunksToUpdate.size() > 0) {
childChunksToUpdate[0].offset = d->chunks[d->childChunkIndex[DIINChunk]].offset + 12;
for(unsigned int i = 1; i < childChunksToUpdate.size(); i++)
@@ -513,6 +606,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
d->format = readBlock(4);
// + 12: chunk header at least, fix for additional junk bytes
while(tell() + 12 <= length()) {
ByteVector chunkName = readBlock(4);
unsigned long long chunkSize = readBlock(8).toLongLong(bigEndian);
@@ -523,7 +617,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
break;
}
if(static_cast<unsigned long long>(tell()) + chunkSize > static_cast<unsigned long long>(length())) {
if(static_cast<unsigned long long>(tell()) + chunkSize >
static_cast<unsigned long long>(length())) {
debug("DSDIFF::File::read() -- Chunk '" + chunkName
+ "' has invalid size (larger than the file size)");
setValid(false);
@@ -538,6 +633,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
seek(chunk.size, Current);
// Check padding
chunk.padding = 0;
long uPosNotPadded = tell();
if((uPosNotPadded & 0x01) != 0) {
@@ -551,10 +647,14 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
d->chunks.push_back(chunk);
}
unsigned long long lengthDSDSamplesTimeChannels = 0; // For DSD uncompressed
unsigned long long audioDataSizeinBytes = 0; // For computing bitrate
unsigned long dstNumFrames = 0; // For DST compressed frames
unsigned short dstFrameRate = 0; // For DST compressed frames
// For DSD uncompressed
unsigned long long lengthDSDSamplesTimeChannels = 0;
// For computing bitrate
unsigned long long audioDataSizeinBytes = 0;
// For DST compressed frames
unsigned long dstNumFrames = 0;
// For DST compressed frames
unsigned short dstFrameRate = 0;
for(unsigned int i = 0; i < d->chunks.size(); i++) {
if(d->chunks[i].name == "DSD ") {
@@ -589,7 +689,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
// Found the DST frame information chunk
dstNumFrames = readBlock(4).toUInt(bigEndian);
dstFrameRate = readBlock(2).toUShort(bigEndian);
break; // Found the wanted one, no need to look at the others
// Found the wanted one, no need to look at the others
break;
}
seek(dstChunkSize, Current);
@@ -608,7 +709,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
d->childChunkIndex[PROPChunk] = i;
// Now decodes the chunks inside the PROP chunk
long long propChunkEnd = d->chunks[i].offset + d->chunks[i].size;
seek(d->chunks[i].offset + 4); // +4 to remove the 'SND ' marker at beginning of 'PROP' chunk
// +4 to remove the 'SND ' marker at beginning of 'PROP' chunk
seek(d->chunks[i].offset + 4);
while(tell() + 12 <= propChunkEnd) {
ByteVector propChunkName = readBlock(4);
long long propChunkSize = readBlock(8).toLongLong(bigEndian);
@@ -650,7 +752,9 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
else if(d->chunks[i].name == "DIIN") {
d->childChunkIndex[DIINChunk] = i;
d->hasDiin = true;
// Now decode the chunks inside the DIIN chunk
long long diinChunkEnd = d->chunks[i].offset + d->chunks[i].size;
seek(d->chunks[i].offset);
@@ -679,8 +783,10 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
seek(chunk.size, Current);
// Check padding
chunk.padding = 0;
long uPosNotPadded = tell();
if((uPosNotPadded & 0x01) != 0) {
ByteVector iByte = readBlock(1);
if((iByte.size() != 1) || (iByte[0] != 0))
@@ -715,10 +821,12 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
unsigned short channels=0;
for(unsigned int i = 0; i < d->childChunks[PROPChunk].size(); i++) {
if(d->childChunks[PROPChunk][i].name == "ID3 " || d->childChunks[PROPChunk][i].name == "id3 ") {
if(d->childChunks[PROPChunk][i].name == "ID3 " ||
d->childChunks[PROPChunk][i].name == "id3 ") {
if(d->hasID3v2) {
d->duplicateID3V2chunkIndex = i;
continue; // ID3V2 tag has already been found at root level
// ID3V2 tag has already been found at root level
continue;
}
d->id3v2TagChunkID = d->childChunks[PROPChunk][i].name;
d->tag.set(ID3v2Index, new ID3v2::Tag(this, d->childChunks[PROPChunk][i].offset));
@@ -738,6 +846,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
}
// Read title & artist from DIIN chunk
d->tag.access<DSDIFF::DIIN::Tag>(DIINIndex, true);
if(d->hasDiin) {
@@ -765,8 +874,9 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if(lengthDSDSamplesTimeChannels == 0) {
// DST compressed signal : need to compute length of DSD uncompressed frames
if(dstFrameRate > 0)
lengthDSDSamplesTimeChannels = (unsigned long long)dstNumFrames
* (unsigned long long)sampleRate / (unsigned long long)dstFrameRate;
lengthDSDSamplesTimeChannels = (unsigned long long) dstNumFrames *
(unsigned long long) sampleRate /
(unsigned long long) dstFrameRate;
else
lengthDSDSamplesTimeChannels = 0;
}
@@ -777,7 +887,7 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
}
int bitrate = 0;
if(lengthDSDSamplesTimeChannels > 0)
bitrate = (audioDataSizeinBytes*8*sampleRate) / lengthDSDSamplesTimeChannels / 1000;
bitrate = (audioDataSizeinBytes * 8 * sampleRate) / lengthDSDSamplesTimeChannels / 1000;
d->properties = new Properties(sampleRate,
channels,
@@ -788,7 +898,8 @@ void DSDIFF::File::read(bool readProperties, Properties::ReadStyle propertiesSty
if(!ID3v2Tag()) {
d->tag.access<ID3v2::Tag>(ID3v2Index, true);
d->isID3InPropChunk = false; // By default, ID3 chunk is at root level
// By default, ID3 chunk is at root level
d->isID3InPropChunk = false;
d->hasID3v2 = false;
}
}

View File

@@ -41,27 +41,43 @@ namespace TagLib {
*
* This supports an ID3v2 tag as well as reading stream from the ID3 RIFF
* chunk as well as properties from the file.
* Description of the DSDIFF format is available
* Description of the DSDIFF format is available
* at http://dsd-guide.com/sites/default/files/white-papers/DSDIFF_1.5_Spec.pdf
* DSDIFF standard does not explictly specify the ID3V2 chunk
* DSDIFF standard does not explicitly specify the ID3V2 chunk
* It can be found at the root level, but also sometimes inside the PROP chunk
* In addition, title and artist info are stored as part of the standard
*/
namespace DSDIFF {
//! An implementation of Strawberry_TagLib::TagLib::File with DSDIFF specific methods
//! An implementation of TagLib::File with DSDIFF specific methods
/*!
* This implements and provides an interface for DSDIFF files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to DSDIFF files.
*/
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File
{
public:
/*!
* This set of flags is used for various operations and is suitable for
* being OR-ed together.
*/
enum TagTypes {
//! Empty set. Matches no tag types.
NoTags = 0x0000,
//! Matches DIIN tags.
DIIN = 0x0002,
//! Matches ID3v1 tags.
ID3v2 = 0x0002,
//! Matches all tag types.
AllTags = 0xffff
};
/*!
* Constructs an DSDIFF file from \a file. If \a readProperties is true
* the file's audio properties will also be read.
@@ -115,13 +131,13 @@ namespace TagLib {
*
* \see hasID3v2Tag()
*/
virtual ID3v2::Tag *ID3v2Tag() const;
ID3v2::Tag *ID3v2Tag(bool create = false) const;
/*!
* Returns the DSDIFF DIIN Tag for this file
*
*/
DSDIFF::DIIN::Tag *DIINTag() const;
DSDIFF::DIIN::Tag *DIINTag(bool create = false) const;
/*!
* Implements the unified property interface -- export function.
@@ -161,15 +177,21 @@ namespace TagLib {
virtual bool save();
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
*
* This strips all tags not included in the mask, but does not modify them
* in memory, so later calls to save() which make use of these tags will
* remain valid. This also strips empty tags.
* Save the file. If \a strip is specified, it is possible to choose if
* tags not specified in \a tags should be stripped from the file or
* retained. With \a version, it is possible to specify whether ID3v2.4
* or ID3v2.3 should be used.
*/
bool save(int tags);
bool save(TagTypes tags, StripTags strip = StripOthers, ID3v2::Version version = ID3v2::v4);
/*!
* This will strip the tags that match the OR-ed together TagTypes from the
* file. By default it strips all tags. It returns true if the tags are
* successfully stripped.
*
* \note This will update the file immediately.
*/
void strip(TagTypes tags = AllTags);
/*!
* Returns whether or not the file on disk actually has an ID3v2 tag.
@@ -179,8 +201,8 @@ namespace TagLib {
bool hasID3v2Tag() const;
/*!
* Returns whether or not the file on disk actually has the DSDIFF
* Title & Artist tag.
* Returns whether or not the file on disk actually has the DSDIFF
* title and artist tags.
*
* \see DIINTag()
*/
@@ -205,6 +227,10 @@ namespace TagLib {
File(const File &);
File &operator=(const File &);
void removeRootChunk(const ByteVector &id);
void removeRootChunk(unsigned int chunk);
void removeChildChunk(unsigned int i, unsigned int chunk);
/*!
* Sets the data for the the specified chunk at root level to \a data.
*

View File

@@ -56,7 +56,7 @@ namespace TagLib {
{
public:
/*!
* Contructs an DSF file from \a file. If \a readProperties is true the
* Constructs an DSF file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*/
@@ -64,7 +64,7 @@ namespace TagLib {
Properties::ReadStyle propertiesStyle = Properties::Average);
/*!
* Contructs an DSF file from \a file. If \a readProperties is true the
* Constructs an DSF file from \a file. If \a readProperties is true the
* file's audio properties will also be read using \a propertiesStyle. If
* false, \a propertiesStyle is ignored.
*/

View File

@@ -42,7 +42,7 @@ namespace TagLib {
/*!
* FileRef exists to provide a minimal, generic and value-based wrapper around
* a File. It is lightweight and implicitly shared, and as such suitable for
* pass-by-value use. This hides some of the uglier details of Strawberry_TagLib::TagLib::File
* pass-by-value use. This hides some of the uglier details of TagLib::File
* and the non-generic portions of the concrete file implementations.
*
* This class is useful in a "simple usage" situation where it is desirable

View File

@@ -55,12 +55,12 @@ namespace TagLib {
namespace FLAC {
//! An implementation of Strawberry_TagLib::TagLib::File with FLAC specific methods
//! An implementation of TagLib::File with FLAC specific methods
/*!
* This implements and provides an interface for FLAC files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to FLAC files.
*/
@@ -241,7 +241,7 @@ namespace TagLib {
* \see ID3v2FrameFactory
* \deprecated This value should be passed in via the constructor
*/
void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
TAGLIB_DEPRECATED void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
/*!
* Returns the block of data used by FLAC::Properties for parsing the
@@ -249,7 +249,7 @@ namespace TagLib {
*
* \deprecated Always returns an empty vector.
*/
ByteVector streamInfoData(); // BIC: remove
TAGLIB_DEPRECATED ByteVector streamInfoData(); // BIC: remove
/*!
* Returns the length of the audio-stream, used by FLAC::Properties for
@@ -257,7 +257,7 @@ namespace TagLib {
*
* \deprecated Always returns zero.
*/
long streamLength(); // BIC: remove
TAGLIB_DEPRECATED long streamLength(); // BIC: remove
/*!
* Returns a list of pictures attached to the FLAC file.

View File

@@ -73,7 +73,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
@@ -121,7 +121,7 @@ namespace TagLib {
*
* \deprecated
*/
int sampleWidth() const;
TAGLIB_DEPRECATED int sampleWidth() const;
/*!
* Return the number of sample frames.

View File

@@ -277,7 +277,7 @@ void IT::File::read(bool)
// in the instrument/sample names and more characters
// afterwards. The spec does not mention such a case.
// Currently I just discard anything after a nil, but
// e.g. VLC seems to interprete a nil as a space. I
// e.g. VLC seems to interpret a nil as a space. I
// don't know what is the proper behaviour.
for(unsigned short i = 0; i < instrumentCount; ++ i) {
seek(192L + length + ((long)i << 2));

View File

@@ -42,8 +42,8 @@ namespace TagLib {
/*!
* This implements and provides an interface for MP4 files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to MP4 files.
*/
class TAGLIB_EXPORT File : public Strawberry_TagLib::TagLib::File
@@ -79,7 +79,7 @@ namespace TagLib {
* Returns a pointer to the MP4 tag of the file.
*
* MP4::Tag implements the tag interface, so this serves as the
* reimplementation of Strawberry_TagLib::TagLib::File::tag().
* reimplementation of TagLib::File::tag().
*
* \note The Tag <b>is still</b> owned by the MP4::File and should not be
* deleted by the user. It will be deleted when the file (object) is

View File

@@ -58,7 +58,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -74,9 +74,20 @@ MP4::Tag::Tag(Strawberry_TagLib::TagLib::File *file, MP4::Atoms *atoms) :
atom->name == "hdvd" || atom->name == "shwm") {
parseBool(atom);
}
else if(atom->name == "tmpo" || atom->name == "rate" || atom->name == "\251mvi" || atom->name == "\251mvc") {
else if(atom->name == "tmpo" || atom->name == "\251mvi" || atom->name == "\251mvc") {
parseInt(atom);
}
else if(atom->name == "rate") {
AtomDataList data = parseData2(atom);
if(!data.isEmpty()) {
AtomData val = data[0];
if (val.type == TypeUTF8) {
addItem(atom->name, StringList(String(val.data, String::UTF8)));
} else {
addItem(atom->name, (int)(val.data.toShort()));
}
}
}
else if(atom->name == "tvsn" || atom->name == "tves" || atom->name == "cnID" ||
atom->name == "sfID" || atom->name == "atID" || atom->name == "geID" ||
atom->name == "cmID") {
@@ -480,9 +491,19 @@ MP4::Tag::save()
name == "shwm") {
data.append(renderBool(name.data(String::Latin1), it->second));
}
else if(name == "tmpo" || name == "rate" || name == "\251mvi" || name == "\251mvc") {
else if(name == "tmpo" || name == "\251mvi" || name == "\251mvc") {
data.append(renderInt(name.data(String::Latin1), it->second));
}
else if (name == "rate") {
const MP4::Item& item = it->second;
StringList value = item.toStringList();
if (value.isEmpty()) {
data.append(renderInt(name.data(String::Latin1), item));
}
else {
data.append(renderText(name.data(String::Latin1), item));
}
}
else if(name == "tvsn" || name == "tves" || name == "cnID" ||
name == "sfID" || name == "atID" || name == "geID" ||
name == "cmID") {
@@ -784,13 +805,23 @@ MP4::Tag::setGenre(const String &value)
void
MP4::Tag::setYear(unsigned int value)
{
d->items["\251day"] = StringList(String::number(value));
if (value == 0) {
d->items.erase("\251day");
}
else {
d->items["\251day"] = StringList(String::number(value));
}
}
void
MP4::Tag::setTrack(unsigned int value)
{
d->items["trkn"] = MP4::Item(value, 0);
if (value == 0) {
d->items.erase("trkn");
}
else {
d->items["trkn"] = MP4::Item(value, 0);
}
}
bool MP4::Tag::isEmpty() const

View File

@@ -43,7 +43,7 @@ namespace TagLib {
/*!
* \deprecated
*/
typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemListMap;
TAGLIB_DEPRECATED typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemListMap;
typedef Strawberry_TagLib::TagLib::Map<String, Item> ItemMap;
class TAGLIB_EXPORT Tag: public Strawberry_TagLib::TagLib::Tag
@@ -75,7 +75,7 @@ namespace TagLib {
/*!
* \deprecated Use the item() and setItem() API instead
*/
ItemMap &itemListMap();
TAGLIB_DEPRECATED ItemMap &itemListMap();
/*!
* Returns a string-keyed map of the MP4::Items for this tag.

View File

@@ -54,12 +54,12 @@ namespace TagLib {
namespace MPC {
//! An implementation of Strawberry_TagLib::TagLib::File with MPC specific methods
//! An implementation of TagLib::File with MPC specific methods
/*!
* This implements and provides an interface for MPC files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to MPC files.
* The only invalid tag combination supported is an ID3v1 tag after an APE tag.
*/
@@ -199,7 +199,7 @@ namespace TagLib {
* \deprecated
* \see strip
*/
void remove(int tags = AllTags);
TAGLIB_DEPRECATED void remove(int tags = AllTags);
/*!
* Returns whether or not the file on disk actually has an ID3v1 tag.

View File

@@ -49,18 +49,17 @@ public:
albumGain(0),
albumPeak(0) {}
int version;
int length;
int bitrate;
int sampleRate;
int channels;
int version;
int length;
int bitrate;
int sampleRate;
int channels;
unsigned int totalFrames;
unsigned int sampleFrames;
unsigned int trackGain;
unsigned int trackPeak;
unsigned int albumGain;
unsigned int albumPeak;
String flags;
int trackGain;
int trackPeak;
int albumGain;
int albumPeak;
};
////////////////////////////////////////////////////////////////////////////////
@@ -312,9 +311,9 @@ void MPC::Properties::readSV7(const ByteVector &data, long streamLength)
const unsigned int gapless = data.toUInt(5, false);
d->trackGain = data.toShort(14, false);
d->trackPeak = data.toShort(12, false);
d->trackPeak = data.toUShort(12, false);
d->albumGain = data.toShort(18, false);
d->albumPeak = data.toShort(16, false);
d->albumPeak = data.toUShort(16, false);
// convert gain info
if(d->trackGain != 0) {

View File

@@ -75,7 +75,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -89,7 +89,7 @@ namespace TagLib {
* This is an implementation of the ID3v1 format. ID3v1 is both the simplest
* and most common of tag formats but is rather limited. Because of its
* pervasiveness and the way that applications have been written around the
* fields that it provides, the generic Strawberry_TagLib::TagLib::Tag API is a mirror of what is
* fields that it provides, the generic TagLib::Tag API is a mirror of what is
* provided by ID3v1.
*
* ID3v1 tags should generally only contain Latin1 information. However because

View File

@@ -267,7 +267,7 @@ void ChapterFrame::parseFields(const ByteVector &data)
return;
while(embPos < size - header()->size()) {
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), (d->tagHeader != 0));
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), d->tagHeader);
if(!frame)
return;

View File

@@ -132,12 +132,12 @@ namespace TagLib {
/*!
* \deprecated Always returns master volume.
*/
ChannelType channelType() const;
TAGLIB_DEPRECATED ChannelType channelType() const;
/*!
* \deprecated This method no longer has any effect.
*/
void setChannelType(ChannelType t);
TAGLIB_DEPRECATED void setChannelType(ChannelType t);
/*
* There was a terrible API goof here, and while this can't be changed to

View File

@@ -55,7 +55,7 @@ public:
namespace {
// These functions are needed to try to aim for backward compatibility with
// an API that previously (unreasonably) required null bytes to be appeneded
// an API that previously (unreasonably) required null bytes to be appended
// at the end of identifiers explicitly by the API user.
// BIC: remove these
@@ -304,7 +304,7 @@ void TableOfContentsFrame::parseFields(const ByteVector &data)
return;
while(embPos < size - header()->size()) {
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), (d->tagHeader != 0));
Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), d->tagHeader);
if(!frame)
return;

View File

@@ -277,7 +277,7 @@ PropertyMap TextIdentificationFrame::makeTIPLProperties() const
break;
}
if(!found){
// invalid involved role -> mark whole frame as unsupported in order to be consisten with writing
// invalid involved role -> mark whole frame as unsupported in order to be consistent with writing
map.clear();
map.unsupportedData().append(frameID());
return map;

26
3rdparty/taglib/mpeg/id3v2/id3v2.h vendored Normal file
View File

@@ -0,0 +1,26 @@
#ifndef TAGLIB_ID3V2_H
#define TAGLIB_ID3V2_H
namespace Strawberry_TagLib {
namespace TagLib {
//! An ID3v2 implementation
/*!
* This is a relatively complete and flexible framework for working with ID3v2
* tags.
*
* \see ID3v2::Tag
*/
namespace ID3v2 {
/*!
* Used to specify which version of the ID3 standard to use when saving tags.
*/
enum Version {
v3 = 3, //<! ID3v2.3
v4 = 4 //<! ID3v2.4
};
}
}
}
#endif

View File

@@ -39,7 +39,7 @@ namespace TagLib {
/*!
* This class implements ID3v2 extended headers. It attempts to follow,
* both semantically and programatically, the structure specified in
* both semantically and programmatically, the structure specified in
* the ID3v2 standard. The API is based on the properties of ID3v2 extended
* headers specified there. If any of the terms used in this documentation
* are unclear please check the specification in the linked section.

View File

@@ -111,8 +111,8 @@ Frame *Frame::createTextualFrame(const String &key, const StringList &values) //
// check if the key is contained in the key<=>frameID mapping
ByteVector frameID = keyToFrameID(key);
if(!frameID.isEmpty()) {
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number) are in fact text frames.
if(frameID[0] == 'T' || frameID == "WFED" || frameID == "MVNM" || frameID == "MVIN"){ // text frame
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number), GRP1 (Grouping) are in fact text frames.
if(frameID[0] == 'T' || frameID == "WFED" || frameID == "MVNM" || frameID == "MVIN" || frameID == "GRP1"){ // text frame
TextIdentificationFrame *frame = new TextIdentificationFrame(frameID, String::UTF8);
frame->setText(values);
return frame;
@@ -394,6 +394,7 @@ namespace
{ "WFED", "PODCASTURL" },
{ "MVNM", "MOVEMENTNAME" },
{ "MVIN", "MOVEMENTNUMBER" },
{ "GRP1", "GROUPING" },
};
const size_t frameTranslationSize = sizeof(frameTranslation) / sizeof(frameTranslation[0]);
@@ -476,8 +477,8 @@ PropertyMap Frame::asProperties() const
// workaround until this function is virtual
if(id == "TXXX")
return dynamic_cast< const UserTextIdentificationFrame* >(this)->asProperties();
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number) are in fact text frames.
else if(id[0] == 'T' || id == "WFED" || id == "MVNM" || id == "MVIN")
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number), GRP1 (Grouping) are in fact text frames.
else if(id[0] == 'T' || id == "WFED" || id == "MVNM" || id == "MVIN" || id == "GRP1")
return dynamic_cast< const TextIdentificationFrame* >(this)->asProperties();
else if(id == "WXXX")
return dynamic_cast< const UserUrlLinkFrame* >(this)->asProperties();

View File

@@ -90,14 +90,15 @@ namespace TagLib {
* non-binary compatible release this will be made into a non-static
* member that checks the internal ID3v2 version.
*/
static unsigned int headerSize(); // BIC: remove and make non-static
static unsigned int headerSize(); // BIC: make non-static
/*!
* Returns the size of the frame header for the given ID3v2 version.
*
* \deprecated Please see the explanation above.
*/
static unsigned int headerSize(unsigned int version); // BIC: remove and make non-static
// BIC: remove
static unsigned int headerSize(unsigned int version);
/*!
* Sets the data that will be used as the frame. Since the length is not
@@ -225,7 +226,7 @@ namespace TagLib {
* This is useful for reading strings sequentially.
*/
String readStringField(const ByteVector &data, String::Type encoding,
int *positon = 0);
int *position = 0);
/*!
* Checks a the list of string values to see if they can be used with the
@@ -256,7 +257,7 @@ namespace TagLib {
/*!
* Parses the contents of this frame as PropertyMap. If that fails, the returend
* Parses the contents of this frame as PropertyMap. If that fails, the returned
* PropertyMap will be empty, and its unsupportedData() will contain this frame's
* ID.
* BIC: Will be a virtual function in future releases.
@@ -335,7 +336,7 @@ namespace TagLib {
* \deprecated Please use the constructor below that accepts a version
* number.
*/
Header(const ByteVector &data, bool synchSafeInts);
TAGLIB_DEPRECATED Header(const ByteVector &data, bool synchSafeInts);
/*!
* Construct a Frame Header based on \a data. \a data must at least
@@ -412,6 +413,7 @@ namespace TagLib {
* removed in the next binary incompatible release (2.0) and will be
* replaced with a non-static method that checks the frame version.
*/
// BIC: make non-static
static unsigned int size();
/*!
@@ -420,6 +422,7 @@ namespace TagLib {
*
* \deprecated Please see the explanation in the version above.
*/
// BIC: remove
static unsigned int size(unsigned int version);
/*!
@@ -503,7 +506,7 @@ namespace TagLib {
/*!
* \deprecated
*/
bool frameAlterPreservation() const;
TAGLIB_DEPRECATED bool frameAlterPreservation() const;
private:
Header(const Header &);

View File

@@ -126,6 +126,11 @@ Frame *FrameFactory::createFrame(const ByteVector &data, unsigned int version) c
}
Frame *FrameFactory::createFrame(const ByteVector &origData, Header *tagHeader) const
{
return createFrame(origData, const_cast<const Header *>(tagHeader));
}
Frame *FrameFactory::createFrame(const ByteVector &origData, const Header *tagHeader) const
{
ByteVector data = origData;
unsigned int version = tagHeader->majorVersion();
@@ -198,8 +203,8 @@ Frame *FrameFactory::createFrame(const ByteVector &origData, Header *tagHeader)
// Text Identification (frames 4.2)
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number) are in fact text frames.
if(frameID.startsWith("T") || frameID == "WFED" || frameID == "MVNM" || frameID == "MVIN") {
// Apple proprietary WFED (Podcast URL), MVNM (Movement Name), MVIN (Movement Number), GRP1 (Grouping) are in fact text frames.
if(frameID.startsWith("T") || frameID == "WFED" || frameID == "MVNM" || frameID == "MVIN" || frameID == "GRP1") {
TextIdentificationFrame *f = frameID != "TXXX"
? new TextIdentificationFrame(data, header)
@@ -459,6 +464,7 @@ namespace
{ "WFD", "WFED" },
{ "MVN", "MVNM" },
{ "MVI", "MVIN" },
{ "GP1", "GRP1" },
};
const size_t frameConversion2Size = sizeof(frameConversion2) / sizeof(frameConversion2[0]);

View File

@@ -87,12 +87,17 @@ namespace TagLib {
*/
Frame *createFrame(const ByteVector &data, unsigned int version = 4) const;
/*!
* \deprecated
*/
// BIC: remove
Frame *createFrame(const ByteVector &data, Header *tagHeader) const;
/*!
* Create a frame based on \a data. \a tagHeader should be a valid
* ID3v2::Header instance.
*/
// BIC: make virtual
Frame *createFrame(const ByteVector &data, Header *tagHeader) const;
Frame *createFrame(const ByteVector &data, const Header *tagHeader) const;
/*!
* After a tag has been read, this tries to rebuild some of them

View File

@@ -207,14 +207,14 @@ void Header::parse(const ByteVector &data)
if(sizeData.size() != 4) {
d->tagSize = 0;
debug("Strawberry_TagLib::TagLib::ID3v2::Header::parse() - The tag size as read was 0 bytes!");
debug("TagLib::ID3v2::Header::parse() - The tag size as read was 0 bytes!");
return;
}
for(ByteVector::ConstIterator it = sizeData.begin(); it != sizeData.end(); it++) {
if(static_cast<unsigned char>(*it) >= 128) {
d->tagSize = 0;
debug("Strawberry_TagLib::TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
debug("TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128.");
return;
}
}

View File

@@ -28,6 +28,7 @@
#include "tbytevector.h"
#include "taglib_export.h"
#include "id3v2.h"
namespace Strawberry_TagLib {
namespace TagLib {

View File

@@ -462,7 +462,7 @@ PropertyMap ID3v2::Tag::setProperties(const PropertyMap &origProps)
ByteVector ID3v2::Tag::render() const
{
return render(4);
return render(ID3v2::v4);
}
void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
@@ -568,17 +568,17 @@ void ID3v2::Tag::downgradeFrames(FrameList *frames, FrameList *newFrames) const
}
ByteVector ID3v2::Tag::render(int version) const
{
return render(version == 3 ? v3 : v4);
}
ByteVector ID3v2::Tag::render(Version version) const
{
// We need to render the "tag data" first so that we have to correct size to
// render in the tag's header. The "tag data" -- everything that is included
// in ID3v2::Header::tagSize() -- includes the extended header, frames and
// padding, but does not include the tag's header or footer.
if(version != 3 && version != 4) {
debug("Unknown ID3v2 version, using ID3v2.4");
version = 4;
}
// TODO: Render the extended header.
// Downgrade the frames that ID3v2.3 doesn't support.
@@ -587,7 +587,7 @@ ByteVector ID3v2::Tag::render(int version) const
newFrames.setAutoDelete(true);
FrameList frameList;
if(version == 4) {
if(version == v4) {
frameList = d->frameList;
}
else {
@@ -601,7 +601,7 @@ ByteVector ID3v2::Tag::render(int version) const
// Loop through the frames rendering them and adding them to the tagData.
for(FrameList::ConstIterator it = frameList.begin(); it != frameList.end(); it++) {
(*it)->header()->setVersion(version);
(*it)->header()->setVersion(version == v3 ? 3 : 4);
if((*it)->header()->frameID().size() != 4) {
debug("An ID3v2 frame of unsupported or unknown type \'"
+ String((*it)->header()->frameID()) + "\' has been discarded");

View File

@@ -33,6 +33,7 @@
#include "tmap.h"
#include "taglib_export.h"
#include "id3v2.h"
#include "id3v2framefactory.h"
namespace Strawberry_TagLib {
@@ -40,15 +41,6 @@ namespace TagLib {
class File;
//! An ID3v2 implementation
/*!
* This is a relatively complete and flexible framework for working with ID3v2
* tags.
*
* \see ID3v2::Tag
*/
namespace ID3v2 {
class Header;
@@ -126,7 +118,7 @@ namespace TagLib {
* heart and should not be done without much meditation on the spec. It's
* rather long, but if you're planning on messing with this class and others
* that deal with the details of ID3v2 (rather than the nice, safe, abstract
* Strawberry_TagLib::TagLib::Tag and friends), it's worth your time to familiarize yourself
* TagLib::Tag and friends), it's worth your time to familiarize yourself
* with said spec (which is distributed with the TagLib sources). TagLib
* tries to do most of the work, but with a little luck, you can still
* convince it to generate invalid ID3v2 tags. The APIs for ID3v2 assume a
@@ -202,7 +194,7 @@ namespace TagLib {
* prone to change my mind, so this gets to stay around until near a
* release.
*/
Footer *footer() const;
TAGLIB_DEPRECATED Footer *footer() const;
/*!
* Returns a reference to the frame list map. This is an FrameListMap of
@@ -217,7 +209,7 @@ namespace TagLib {
* beats per minute -- the TBPM frame.
*
* \code
* Strawberry_TagLib::TagLib::MPEG::File f("foo.mp3");
* TagLib::MPEG::File f("foo.mp3");
*
* // Check to make sure that it has an ID3v2 tag
*
@@ -225,7 +217,7 @@ namespace TagLib {
*
* // Get the list of frames for a specific frame type
*
* Strawberry_TagLib::TagLib::ID3v2::FrameList l = f.ID3v2Tag()->frameListMap()["TBPM"];
* TagLib::ID3v2::FrameList l = f.ID3v2Tag()->frameListMap()["TBPM"];
*
* if(!l.isEmpty())
* std::cout << l.front()->toString() << std::endl;
@@ -311,7 +303,7 @@ namespace TagLib {
* - otherwise, the key "LYRICS:<description>" is used;
* - if the frame ID is "TIPL" (involved peoples list), and if all the
* roles defined in the frame are known in TextIdentificationFrame::involvedPeopleMap(),
* then "<role>=<name>" will be contained in the returned obejct for each
* then "<role>=<name>" will be contained in the returned object for each
* - if the frame ID is "TMCL" (musician credit list), then
* "PERFORMER:<instrument>=<name>" will be contained in the returned
* PropertyMap for each defined musician
@@ -346,14 +338,18 @@ namespace TagLib {
*/
ByteVector render() const;
/*!
* \deprecated
*/
TAGLIB_DEPRECATED ByteVector render(int version) const;
/*!
* Render the tag back to binary data, suitable to be written to disk.
*
* The \a version parameter specifies the version of the rendered
* ID3v2 tag. It can be either 4 or 3.
* The \a version parameter specifies whether ID3v2.4 (default) or ID3v2.3
* should be used.
*/
// BIC: combine with the above method
ByteVector render(int version) const;
ByteVector render(Version version) const;
/*!
* Gets the current string handler that decides how the "Latin-1" data
@@ -397,6 +393,9 @@ namespace TagLib {
*/
void setTextFrame(const ByteVector &id, const String &value);
/*!
* Dowgrade frames from ID3v2.4 (used internally and by default) to ID3v2.3
*/
void downgradeFrames(FrameList *existingFrames, FrameList *newFrames) const;
private:

View File

@@ -109,8 +109,8 @@ bool MPEG::File::isSupported(IOStream *stream)
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), true, &headerOffset);
if(buffer.isEmpty())
return false;
return false;
const long originalPosition = stream->tell();
AdapterFile file(stream);
@@ -200,20 +200,30 @@ bool MPEG::File::save()
bool MPEG::File::save(int tags)
{
return save(tags, true);
return save(tags, StripOthers);
}
bool MPEG::File::save(int tags, bool stripOthers)
{
return save(tags, stripOthers, 4);
return save(tags, stripOthers ? StripOthers : StripNone, ID3v2::v4);
}
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version)
{
return save(tags, stripOthers, id3v2Version, true);
return save(tags,
stripOthers ? StripOthers : StripNone,
id3v2Version == 3 ? ID3v2::v3 : ID3v2::v4);
}
bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags)
{
return save(tags,
stripOthers ? StripOthers : StripNone,
id3v2Version == 3 ? ID3v2::v3 : ID3v2::v4,
duplicateTags ? Duplicate : DoNotDuplicate);
}
bool MPEG::File::save(int tags, StripTags strip, ID3v2::Version version, DuplicateTags duplicate)
{
if(readOnly()) {
debug("MPEG::File::save() -- File is read only.");
@@ -222,22 +232,22 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// Create the tags if we've been asked to.
if(duplicateTags) {
if(duplicate == Duplicate) {
// Copy the values from the tag that does exist into the new tag,
// except if the existing tag is to be stripped.
if((tags & ID3v2) && ID3v1Tag() && !(stripOthers && !(tags & ID3v1)))
if((tags & ID3v2) && ID3v1Tag() && !(strip == StripOthers && !(tags & ID3v1)))
Tag::duplicate(ID3v1Tag(), ID3v2Tag(true), false);
if((tags & ID3v1) && d->tag[ID3v2Index] && !(stripOthers && !(tags & ID3v2)))
if((tags & ID3v1) && d->tag[ID3v2Index] && !(strip == StripOthers && !(tags & ID3v2)))
Tag::duplicate(ID3v2Tag(), ID3v1Tag(true), false);
}
// Remove all the tags not going to be saved.
if(stripOthers)
strip(~tags, false);
if(strip == StripOthers)
File::strip(~tags, false);
if(ID3v2 & tags) {
@@ -248,7 +258,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
if(d->ID3v2Location < 0)
d->ID3v2Location = 0;
const ByteVector data = ID3v2Tag()->render(id3v2Version);
const ByteVector data = ID3v2Tag()->render(version);
insert(data, d->ID3v2Location, d->ID3v2OriginalSize);
if(d->APELocation >= 0)
@@ -263,7 +273,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// ID3v2 tag is empty. Remove the old one.
strip(ID3v2, false);
File::strip(ID3v2, false);
}
}
@@ -287,7 +297,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// ID3v1 tag is empty. Remove the old one.
strip(ID3v1, false);
File::strip(ID3v1, false);
}
}
@@ -316,7 +326,7 @@ bool MPEG::File::save(int tags, bool stripOthers, int id3v2Version, bool duplica
// APE tag is empty. Remove the old one.
strip(APE, false);
File::strip(APE, false);
}
}

View File

@@ -32,6 +32,8 @@
#include "mpegproperties.h"
#include "id3v2.h"
namespace Strawberry_TagLib {
namespace TagLib {
@@ -39,14 +41,14 @@ namespace TagLib {
namespace ID3v1 { class Tag; }
namespace APE { class Tag; }
//! An implementation of Strawberry_TagLib::TagLib::File with MPEG (MP3) specific methods
//! An implementation of TagLib::File with MPEG (MP3) specific methods
namespace MPEG {
//! An MPEG file class with some useful methods specific to MPEG
/*!
* This implements the generic Strawberry_TagLib::TagLib::File API and additionally provides
* This implements the generic TagLib::File API and additionally provides
* access to properties that are distinct to MPEG files, notably access
* to the different ID3 tags.
*/
@@ -192,49 +194,39 @@ namespace TagLib {
bool save(int tags);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
* \deprecated
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers);
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers);
/*!
* \deprecated
*/
// BIC: combine with the above method
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers, int id3v2Version);
/*!
* \deprecated
*/
// BIC: combine with the above method
TAGLIB_DEPRECATED bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
* specified by OR-ing together TagTypes values.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
* \a strip can be set to strip all tags except those in \a tags. Those
* tags will not be modified in memory, and thus remain valid.
*
* The \a id3v2Version parameter specifies the version of the saved
* ID3v2 tag. It can be either 4 or 3.
* \a version specifies the ID3v2 version to be used for writing tags. By
* default, the latest standard, ID3v2.4 is used.
*
* If \a duplicate is set to DuplicateTags and at least one tag -- ID3v1
* or ID3v2 -- exists this will duplicate its content into the other tag.
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers, int id3v2Version);
/*!
* Save the file. This will attempt to save all of the tag types that are
* specified by OR-ing together TagTypes values. The save() method above
* uses AllTags. This returns true if saving was successful.
*
* If \a stripOthers is true this strips all tags not included in the mask,
* but does not modify them in memory, so later calls to save() which make
* use of these tags will remain valid. This also strips empty tags.
*
* The \a id3v2Version parameter specifies the version of the saved
* ID3v2 tag. It can be either 4 or 3.
*
* If \a duplicateTags is true and at least one tag -- ID3v1 or ID3v2 --
* exists this will duplicate its content into the other tag.
*/
// BIC: combine with the above method
bool save(int tags, bool stripOthers, int id3v2Version, bool duplicateTags);
bool save(int tags, StripTags strip,
ID3v2::Version version = ID3v2::v4,
DuplicateTags duplicate = Duplicate);
/*!
* Returns a pointer to the ID3v2 tag of the file.
@@ -326,7 +318,7 @@ namespace TagLib {
* \see ID3v2FrameFactory
* \deprecated This value should be passed in via the constructor
*/
void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
TAGLIB_DEPRECATED void setID3v2FrameFactory(const ID3v2::FrameFactory *factory);
/*!
* Returns the position in the file of the first MPEG frame.

View File

@@ -53,7 +53,7 @@ namespace TagLib {
*
* \deprecated
*/
Header(const ByteVector &data);
TAGLIB_DEPRECATED Header(const ByteVector &data);
/*!
* Parses an MPEG header based on \a file and \a offset.

View File

@@ -112,7 +112,7 @@ namespace TagLib {
*
* \deprecated Always returns 0.
*/
static int xingHeaderOffset(Strawberry_TagLib::TagLib::MPEG::Header::Version v,
TAGLIB_DEPRECATED static int xingHeaderOffset(Strawberry_TagLib::TagLib::MPEG::Header::Version v,
Strawberry_TagLib::TagLib::MPEG::Header::ChannelMode c);
private:

View File

@@ -52,12 +52,12 @@ namespace TagLib {
using Strawberry_TagLib::TagLib::FLAC::Properties;
//! An implementation of Strawberry_TagLib::TagLib::File with Ogg/FLAC specific methods
//! An implementation of TagLib::File with Ogg/FLAC specific methods
/*!
* This implements and provides an interface for Ogg/FLAC files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to Ogg FLAC files.
*/

View File

@@ -94,7 +94,7 @@ namespace TagLib {
*
* \deprecated Always returns null.
*/
Page* getCopyWithNewPageSequenceNumber(int sequenceNumber);
TAGLIB_DEPRECATED Page *getCopyWithNewPageSequenceNumber(int sequenceNumber);
/*!
* Returns the index of the first packet wholly or partially contained in

View File

@@ -157,7 +157,7 @@ namespace TagLib {
/*!
* A special value of containing the position of the packet to be
* interpreted by the codec. It is only supported here so that it may be
* coppied from one page to another.
* copied from one page to another.
*
* \see absoluteGranularPosition()
*/

View File

@@ -85,7 +85,7 @@ namespace TagLib {
/*!
* Returns the XiphComment for this file. XiphComment implements the tag
* interface, so this serves as the reimplementation of
* Strawberry_TagLib::TagLib::File::tag().
* TagLib::File::tag().
*/
virtual Ogg::XiphComment *tag() const;

View File

@@ -163,8 +163,14 @@ void Opus::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / 48000.0;
long fileLengthWithoutOverhead = file->length();
// Ignore the two mandatory header packets, see "3. Packet Organization"
// in https://tools.ietf.org/html/rfc7845.html
for (unsigned int i = 0; i < 2; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {

View File

@@ -70,7 +70,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -131,6 +131,7 @@ void Speex::File::read(bool readProperties)
if(!speexHeaderData.startsWith("Speex ")) {
debug("Speex::File::read() -- invalid Speex identification header");
setValid(false);
return;
}

View File

@@ -85,7 +85,7 @@ namespace TagLib {
/*!
* Returns the XiphComment for this file. XiphComment implements the tag
* interface, so this serves as the reimplementation of
* Strawberry_TagLib::TagLib::File::tag().
* TagLib::File::tag().
*/
virtual Ogg::XiphComment *tag() const;

View File

@@ -182,8 +182,14 @@ void Speex::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
long fileLengthWithoutOverhead = file->length();
// Ignore the two header packets, see "Ogg file format" in
// https://www.speex.org/docs/manual/speex-manual/node8.html
for (unsigned int i = 0; i < 2; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {

View File

@@ -70,7 +70,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -92,7 +92,7 @@ namespace TagLib {
/*!
* Returns the XiphComment for this file. XiphComment implements the tag
* interface, so this serves as the reimplementation of
* Strawberry_TagLib::TagLib::File::tag().
* TagLib::File::tag().
*/
virtual Ogg::XiphComment *tag() const;

View File

@@ -188,9 +188,14 @@ void Vorbis::Properties::read(File *file)
if(frameCount > 0) {
const double length = frameCount * 1000.0 / d->sampleRate;
long fileLengthWithoutOverhead = file->length();
// Ignore the three initial header packets, see "1.3.1. Decode Setup" in
// https://xiph.org/vorbis/doc/Vorbis_I_spec.html
for (unsigned int i = 0; i < 3; ++i) {
fileLengthWithoutOverhead -= file->packet(i).size();
}
d->length = static_cast<int>(length + 0.5);
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
d->bitrate = static_cast<int>(fileLengthWithoutOverhead * 8.0 / length + 0.5);
}
}
else {

View File

@@ -76,7 +76,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to

View File

@@ -187,7 +187,7 @@ namespace TagLib {
* \deprecated Using this method may lead to a linkage error.
*/
// BIC: remove and merge with below
void removeField(const String &key, const String &value = String::null);
TAGLIB_DEPRECATED void removeField(const String &key, const String &value = String());
/*!
* Remove all the fields specified by \a key.

View File

@@ -117,6 +117,11 @@ RIFF::AIFF::Properties *RIFF::AIFF::File::audioProperties() const
}
bool RIFF::AIFF::File::save()
{
return save(ID3v2::v4);
}
bool RIFF::AIFF::File::save(ID3v2::Version version)
{
if(readOnly()) {
debug("RIFF::AIFF::File::save() -- File is read only.");
@@ -135,7 +140,7 @@ bool RIFF::AIFF::File::save()
}
if(tag() && !tag()->isEmpty()) {
setChunkData("ID3 ", d->tag->render());
setChunkData("ID3 ", d->tag->render(version));
d->hasID3v2 = true;
}

View File

@@ -46,12 +46,12 @@ namespace TagLib {
namespace AIFF {
//! An implementation of Strawberry_TagLib::TagLib::File with AIFF specific methods
//! An implementation of TagLib::File with AIFF specific methods
/*!
* This implements and provides an interface for AIFF files to the
* Strawberry_TagLib::TagLib::Tag and Strawberry_TagLib::TagLib::AudioProperties interfaces by way of implementing
* the abstract Strawberry_TagLib::TagLib::File API as well as providing some additional
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
* the abstract TagLib::File API as well as providing some additional
* information specific to AIFF files.
*/
@@ -120,6 +120,11 @@ namespace TagLib {
*/
virtual bool save();
/*!
* Save using a specific ID3v2 version (e.g. v3)
*/
bool save(ID3v2::Version version);
/*!
* Returns whether or not the file on disk actually has an ID3v2 tag.
*

View File

@@ -53,7 +53,7 @@ namespace TagLib {
*
* \deprecated
*/
Properties(const ByteVector &data, ReadStyle style);
TAGLIB_DEPRECATED Properties(const ByteVector &data, ReadStyle style);
/*!
* Create an instance of AIFF::Properties with the data read from the
@@ -74,7 +74,7 @@ namespace TagLib {
*
* \deprecated
*/
virtual int length() const;
TAGLIB_DEPRECATED virtual int length() const;
/*!
* Returns the length of the file in seconds. The length is rounded down to
@@ -120,7 +120,7 @@ namespace TagLib {
*
* \deprecated
*/
int sampleWidth() const;
TAGLIB_DEPRECATED int sampleWidth() const;
/*!
* Returns the number of sample frames

View File

@@ -325,9 +325,20 @@ void RIFF::File::read()
if(offset & 1) {
seek(offset);
const ByteVector iByte = readBlock(1);
if(iByte.size() == 1 && iByte[0] == '\0') {
chunk.padding = 1;
offset++;
if(iByte.size() == 1) {
bool skipPadding = iByte[0] == '\0';
if(!skipPadding) {
// Padding byte is not zero, check if it is good to ignore it
const ByteVector fourCcAfterPadding = readBlock(4);
if(isValidChunkName(fourCcAfterPadding)) {
// Use the padding, it is followed by a valid chunk name.
skipPadding = true;
}
}
if(skipPadding) {
chunk.padding = 1;
offset++;
}
}
}

Some files were not shown because too many files have changed in this diff Show More