├── .gitignore ├── LICENSE ├── QBaiduFm.desktop ├── QHotkey ├── QHotkey ├── qhotkey.cpp ├── qhotkey.h ├── qhotkey.pri ├── qhotkey_mac.cpp ├── qhotkey_p.h ├── qhotkey_win.cpp └── qhotkey_x11.cpp ├── README.md ├── aristpicture.cpp ├── aristpicture.h ├── aristpicture.ui ├── baiduFmUi.pro ├── channelswidget.cpp ├── channelswidget.h ├── channelswidget.ui ├── download └── 爱的初体验.mp3 ├── downloadfile.cpp ├── downloadfile.h ├── eventlabel.cpp ├── eventlabel.h ├── getaristpic.cpp ├── getaristpic.h ├── getbaiduchannel.cpp ├── getbaiduchannel.h ├── getcirclescaledpixmap.cpp ├── getcirclescaledpixmap.h ├── getlrc.cpp ├── getlrc.h ├── getsongplaylistid.cpp ├── getsongplaylistid.h ├── getsongreallink.cpp ├── getsongreallink.h ├── img.qrc ├── img ├── back.png ├── backward.svg ├── baidu.jpg ├── baiduFm.png ├── cancel.png ├── cd.png ├── downLoad.png ├── forward.svg ├── handle.png ├── loop_all.svg ├── loop_no.svg ├── loop_one.svg ├── loop_random.svg ├── lrc.svg ├── lyricmask.png ├── menu.svg ├── pause.png ├── pause.svg ├── play.png ├── play.svg ├── setting.png └── volume.png ├── install.sh ├── logindlg.cpp ├── logindlg.h ├── logindlg.ui ├── lyrics.cpp ├── lyrics.h ├── lyrics.ui ├── main.cpp ├── qhotkey.pri ├── screenshot ├── download.png ├── ubuntu.png └── win10.png ├── volpannel.cpp ├── volpannel.h ├── widget.cpp ├── widget.h └── widget.ui /.gitignore: -------------------------------------------------------------------------------- 1 | # C++ objects and libs 2 | 3 | *.slo 4 | *.lo 5 | *.o 6 | *.a 7 | *.la 8 | *.lai 9 | *.so 10 | *.dll 11 | *.dylib 12 | 13 | # Qt-es 14 | 15 | /.qmake.cache 16 | /.qmake.stash 17 | *.pro.user 18 | *.pro.user.* 19 | *.qbs.user 20 | *.qbs.user.* 21 | *.moc 22 | moc_*.cpp 23 | qrc_*.cpp 24 | ui_*.h 25 | Makefile* 26 | *-build-* 27 | 28 | # QtCreator 29 | 30 | *.autosave 31 | 32 | #QtCtreator Qml 33 | *.qmlproject.user 34 | *.qmlproject.user.* 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /QBaiduFm.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=QBaiduFm 3 | Name[zh_CN]=QBaiduFm 4 | Name[zh_HK]=QBaiduFm 5 | Name[zh_TW]=QBaiduFm 6 | GenericName=Music Player 7 | GenericName[af]=Musiekspeler 8 | GenericName[zh_CN]=音乐播放器 9 | GenericName[zh_HK]=音樂播放器 10 | GenericName[zh_TW]=音樂播放器 11 | X-GNOME-FullName=QBaiduFm Music Player 12 | X-GNOME-FullName[zh_CN]=QBaiduFm 音乐播放器 13 | X-GNOME-FullName[zh_HK]=QBaiduFm 音樂播放器 14 | X-GNOME-FullName[zh_TW]=QBaiduFm 音樂播放器 15 | Comment=Play and organize your music collection 16 | Comment[zh_CN]=播放并组织您的音乐收藏 17 | Comment[zh_HK]=播放及管理音樂收藏 18 | Comment[zh_TW]=播放及管理音樂收藏 19 | Keywords=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio; 20 | Keywords[zh_CN]=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio;音频;音乐;歌曲;光盘;播客;播放列表;电台; 21 | Keywords[zh_HK]=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio;音訊;音樂;歌曲;歌;播客;唱片;播放清單;電臺;電台;廣播; 22 | Keywords[zh_TW]=Audio;Song;MP3;CD;Podcast;MTP;iPod;Playlist;Last.fm;UPnP;DLNA;Radio;音訊;音樂;歌曲;歌;播客;唱片;播放清單;電臺;電台;廣播; 23 | Exec=QBaiduFm %U 24 | Terminal=false 25 | Type=Application 26 | Icon=/usr/share/pixmaps/baiduFm.png 27 | Categories=GNOME;GTK;AudioVideo;Audio;Player; 28 | MimeType=application/x-ogg;application/ogg;audio/x-vorbis+ogg;audio/x-scpls;audio/x-mp3;audio/x-mpeg;audio/mpeg;audio/x-mpegurl;audio/x-flac;audio/mp4;x-scheme-handler/itms;x-scheme-handler/itmss; 29 | StartupNotify=true 30 | 31 | -------------------------------------------------------------------------------- /QHotkey/QHotkey: -------------------------------------------------------------------------------- 1 | #include "qhotkey.h" 2 | -------------------------------------------------------------------------------- /QHotkey/qhotkey.cpp: -------------------------------------------------------------------------------- 1 | #include "qhotkey.h" 2 | #include "qhotkey_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | Q_LOGGING_CATEGORY(logQHotkey, "QHotkey") 10 | 11 | QHotkey::QHotkey(QObject *parent) : 12 | QObject(parent), 13 | _keyCode(Qt::Key_unknown), 14 | _modifiers(Qt::NoModifier), 15 | _nativeShortcut(), 16 | _registered(false) 17 | {} 18 | 19 | QHotkey::QHotkey(const QKeySequence &sequence, bool autoRegister, QObject *parent) : 20 | QHotkey(parent) 21 | { 22 | setShortcut(sequence, autoRegister); 23 | } 24 | 25 | QHotkey::QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister, QObject *parent) : 26 | QHotkey(parent) 27 | { 28 | setShortcut(keyCode, modifiers, autoRegister); 29 | } 30 | 31 | QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) : 32 | QHotkey(parent) 33 | { 34 | setNativeShortcut(shortcut, autoRegister); 35 | } 36 | 37 | QHotkey::~QHotkey() 38 | { 39 | if(_registered) 40 | QHotkeyPrivate::instance()->removeShortcut(this); 41 | } 42 | 43 | QKeySequence QHotkey::shortcut() const 44 | { 45 | if(_keyCode == Qt::Key_unknown) 46 | return QKeySequence(); 47 | else 48 | return QKeySequence(_keyCode | _modifiers); 49 | } 50 | 51 | Qt::Key QHotkey::keyCode() const 52 | { 53 | return _keyCode; 54 | } 55 | 56 | Qt::KeyboardModifiers QHotkey::modifiers() const 57 | { 58 | return _modifiers; 59 | } 60 | 61 | QHotkey::NativeShortcut QHotkey::currentNativeShortcut() const 62 | { 63 | return _nativeShortcut; 64 | } 65 | 66 | bool QHotkey::isRegistered() const 67 | { 68 | return _registered; 69 | } 70 | 71 | bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister) 72 | { 73 | if(shortcut.isEmpty()) { 74 | return resetShortcut(); 75 | } else if(shortcut.count() > 1) { 76 | qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! " 77 | "Only the first shortcut will be used!"); 78 | } 79 | 80 | return setShortcut(Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask), 81 | Qt::KeyboardModifiers(shortcut[0] & Qt::KeyboardModifierMask), 82 | autoRegister); 83 | } 84 | 85 | bool QHotkey::setShortcut(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister) 86 | { 87 | if(_registered) { 88 | if(autoRegister) { 89 | if(!QHotkeyPrivate::instance()->removeShortcut(this)) 90 | return false; 91 | } else 92 | return false; 93 | } 94 | 95 | if(keyCode == Qt::Key_unknown) { 96 | _keyCode = Qt::Key_unknown; 97 | _modifiers = Qt::NoModifier; 98 | _nativeShortcut = NativeShortcut(); 99 | return true; 100 | } 101 | 102 | _keyCode = keyCode; 103 | _modifiers = modifiers; 104 | _nativeShortcut = QHotkeyPrivate::instance()->nativeShortcut(keyCode, modifiers); 105 | if(_nativeShortcut.isValid()) { 106 | if(autoRegister) 107 | return QHotkeyPrivate::instance()->addShortcut(this); 108 | else 109 | return true; 110 | } else { 111 | qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << keyCode << "Modifiers:" << modifiers; 112 | _keyCode = Qt::Key_unknown; 113 | _modifiers = Qt::NoModifier; 114 | _nativeShortcut = NativeShortcut(); 115 | return false; 116 | } 117 | } 118 | 119 | bool QHotkey::resetShortcut() 120 | { 121 | if(_registered && 122 | !QHotkeyPrivate::instance()->removeShortcut(this)) { 123 | return false; 124 | } 125 | 126 | _keyCode = Qt::Key_unknown; 127 | _modifiers = Qt::NoModifier; 128 | _nativeShortcut = NativeShortcut(); 129 | return true; 130 | } 131 | 132 | bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister) 133 | { 134 | if(_registered) { 135 | if(autoRegister) { 136 | if(!QHotkeyPrivate::instance()->removeShortcut(this)) 137 | return false; 138 | } else 139 | return false; 140 | } 141 | 142 | if(nativeShortcut.isValid()) { 143 | _keyCode = Qt::Key_unknown; 144 | _modifiers = Qt::NoModifier; 145 | _nativeShortcut = nativeShortcut; 146 | if(autoRegister) 147 | return QHotkeyPrivate::instance()->addShortcut(this); 148 | else 149 | return true; 150 | } else { 151 | _keyCode = Qt::Key_unknown; 152 | _modifiers = Qt::NoModifier; 153 | _nativeShortcut = NativeShortcut(); 154 | return true; 155 | } 156 | } 157 | 158 | bool QHotkey::setRegistered(bool registered) 159 | { 160 | if(_registered && !registered) 161 | return QHotkeyPrivate::instance()->removeShortcut(this); 162 | else if(!_registered && registered) { 163 | if(!_nativeShortcut.isValid()) 164 | return false; 165 | else 166 | return QHotkeyPrivate::instance()->addShortcut(this); 167 | } else 168 | return true; 169 | } 170 | 171 | 172 | 173 | // ---------- QHotkeyPrivate implementation ---------- 174 | 175 | QHotkeyPrivate::QHotkeyPrivate() : 176 | shortcuts() 177 | { 178 | Q_ASSERT_X(qApp, Q_FUNC_INFO, "QHotkey requires QCoreApplication to be instantiated"); 179 | qApp->eventDispatcher()->installNativeEventFilter(this); 180 | } 181 | 182 | QHotkeyPrivate::~QHotkeyPrivate() 183 | { 184 | if(!shortcuts.isEmpty()) 185 | qCWarning(logQHotkey) << "QHotkeyPrivate destroyed with registered shortcuts!"; 186 | if(qApp && qApp->eventDispatcher()) 187 | qApp->eventDispatcher()->removeNativeEventFilter(this); 188 | } 189 | 190 | QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcut(Qt::Key keycode, Qt::KeyboardModifiers modifiers) 191 | { 192 | Qt::ConnectionType conType = (QThread::currentThread() == thread() ? 193 | Qt::DirectConnection : 194 | Qt::BlockingQueuedConnection); 195 | QHotkey::NativeShortcut res; 196 | if(!QMetaObject::invokeMethod(this, "nativeShortcutInvoked", conType, 197 | Q_RETURN_ARG(QHotkey::NativeShortcut, res), 198 | Q_ARG(Qt::Key, keycode), 199 | Q_ARG(Qt::KeyboardModifiers, modifiers))) { 200 | return QHotkey::NativeShortcut(); 201 | } else 202 | return res; 203 | } 204 | 205 | bool QHotkeyPrivate::addShortcut(QHotkey *hotkey) 206 | { 207 | if(hotkey->_registered) 208 | return false; 209 | 210 | Qt::ConnectionType conType = (QThread::currentThread() == thread() ? 211 | Qt::DirectConnection : 212 | Qt::BlockingQueuedConnection); 213 | bool res = false; 214 | if(!QMetaObject::invokeMethod(this, "addShortcutInvoked", conType, 215 | Q_RETURN_ARG(bool, res), 216 | Q_ARG(QHotkey*, hotkey))) { 217 | return false; 218 | } else { 219 | if(res) 220 | emit hotkey->registeredChanged(true); 221 | return res; 222 | } 223 | } 224 | 225 | bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey) 226 | { 227 | if(!hotkey->_registered) 228 | return false; 229 | 230 | Qt::ConnectionType conType = (QThread::currentThread() == thread() ? 231 | Qt::DirectConnection : 232 | Qt::BlockingQueuedConnection); 233 | bool res = false; 234 | if(!QMetaObject::invokeMethod(this, "removeShortcutInvoked", conType, 235 | Q_RETURN_ARG(bool, res), 236 | Q_ARG(QHotkey*, hotkey))) { 237 | return false; 238 | } else { 239 | if(res) 240 | emit hotkey->registeredChanged(false); 241 | return res; 242 | } 243 | } 244 | 245 | void QHotkeyPrivate::activateShortcut(QHotkey::NativeShortcut shortcut) 246 | { 247 | QMetaMethod signal = QMetaMethod::fromSignal(&QHotkey::activated); 248 | for(QHotkey *hkey : shortcuts.values(shortcut)) 249 | signal.invoke(hkey, Qt::QueuedConnection); 250 | } 251 | 252 | bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey) 253 | { 254 | QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut; 255 | 256 | if(!shortcuts.contains(shortcut)) { 257 | if(!registerShortcut(shortcut)) 258 | return false; 259 | } 260 | 261 | shortcuts.insert(shortcut, hotkey); 262 | hotkey->_registered = true; 263 | return true; 264 | } 265 | 266 | bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey) 267 | { 268 | QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut; 269 | 270 | if(shortcuts.remove(shortcut, hotkey) == 0) 271 | return false; 272 | hotkey->_registered = false; 273 | emit hotkey->registeredChanged(true); 274 | if(shortcuts.count(shortcut) == 0) 275 | return unregisterShortcut(shortcut); 276 | else 277 | return true; 278 | } 279 | 280 | QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers) 281 | { 282 | return {this->nativeKeycode(keycode), this->nativeModifiers(modifiers)}; 283 | } 284 | 285 | 286 | 287 | QHotkey::NativeShortcut::NativeShortcut() : 288 | key(), 289 | modifier(), 290 | valid(false) 291 | {} 292 | 293 | QHotkey::NativeShortcut::NativeShortcut(quint32 key, quint32 modifier) : 294 | key(key), 295 | modifier(modifier), 296 | valid(true) 297 | {} 298 | 299 | bool QHotkey::NativeShortcut::isValid() const 300 | { 301 | return valid; 302 | } 303 | 304 | bool QHotkey::NativeShortcut::operator ==(const QHotkey::NativeShortcut &other) const 305 | { 306 | return (key == other.key) && 307 | (modifier == other.modifier) && 308 | valid == other.valid; 309 | } 310 | 311 | bool QHotkey::NativeShortcut::operator !=(const QHotkey::NativeShortcut &other) const 312 | { 313 | return (key != other.key) || 314 | (modifier != other.modifier) || 315 | valid != other.valid; 316 | } 317 | 318 | uint qHash(const QHotkey::NativeShortcut &key) 319 | { 320 | return qHash(key.key) ^ qHash(key.modifier); 321 | } 322 | 323 | uint qHash(const QHotkey::NativeShortcut &key, uint seed) 324 | { 325 | return qHash(key.key, seed) ^ qHash(key.modifier, seed); 326 | } 327 | -------------------------------------------------------------------------------- /QHotkey/qhotkey.h: -------------------------------------------------------------------------------- 1 | #ifndef QHOTKEY_H 2 | #define QHOTKEY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | //! A class to define global, systemwide Hotkeys 10 | class QHotkey : public QObject 11 | { 12 | Q_OBJECT 13 | friend class QHotkeyPrivate; 14 | 15 | //! Specifies whether this hotkey is currently registered or not 16 | Q_PROPERTY(bool registered READ isRegistered WRITE setRegistered NOTIFY registeredChanged) 17 | //! Holds the shortcut this hotkey will be triggered on 18 | Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut RESET resetShortcut) 19 | 20 | public: 21 | //! Defines shortcut with native keycodes 22 | class NativeShortcut { 23 | public: 24 | //! The native keycode 25 | quint32 key; 26 | //! The native modifiers 27 | quint32 modifier; 28 | 29 | //! Creates an invalid native shortcut 30 | NativeShortcut(); 31 | //! Creates a valid native shortcut, with the given key and modifiers 32 | NativeShortcut(quint32 key, quint32 modifier = 0); 33 | 34 | //! Checks, whether this shortcut is valid or not 35 | bool isValid() const; 36 | 37 | //! Equality operator 38 | bool operator ==(const NativeShortcut &other) const; 39 | //! Inequality operator 40 | bool operator !=(const NativeShortcut &other) const; 41 | 42 | private: 43 | bool valid; 44 | }; 45 | 46 | //! Constructor 47 | explicit QHotkey(QObject *parent = Q_NULLPTR); 48 | //! Constructs a hotkey with a shortcut and optionally registers it 49 | explicit QHotkey(const QKeySequence &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR); 50 | //! Constructs a hotkey with a key and modifiers and optionally registers it 51 | explicit QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = Q_NULLPTR); 52 | //! Constructs a hotkey from a native shortcut and optionally registers it 53 | explicit QHotkey(const NativeShortcut &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR); 54 | //! Destructor 55 | ~QHotkey(); 56 | 57 | //! READ-Accessor for QHotkey::registered 58 | bool isRegistered() const; 59 | //! READ-Accessor for QHotkey::shortcut - the key and modifiers as a QKeySequence 60 | QKeySequence shortcut() const; 61 | //! READ-Accessor for QHotkey::shortcut - the key only 62 | Qt::Key keyCode() const; 63 | //! READ-Accessor for QHotkey::shortcut - the modifiers only 64 | Qt::KeyboardModifiers modifiers() const; 65 | 66 | //! Get the current native shortcut 67 | NativeShortcut currentNativeShortcut() const; 68 | 69 | public slots: 70 | //! WRITE-Accessor for QHotkey::registered 71 | bool setRegistered(bool registered); 72 | 73 | //! WRITE-Accessor for QHotkey::shortcut 74 | bool setShortcut(const QKeySequence &shortcut, bool autoRegister = false); 75 | //! WRITE-Accessor for QHotkey::shortcut 76 | bool setShortcut(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false); 77 | //! RESET-Accessor for QHotkey::shortcut 78 | bool resetShortcut(); 79 | 80 | //! Set this hotkey to a native shortcut 81 | bool setNativeShortcut(NativeShortcut nativeShortcut, bool autoRegister = false); 82 | 83 | signals: 84 | //! Will be emitted if the shortcut is pressed 85 | void activated(QPrivateSignal); 86 | 87 | //! NOTIFY-Accessor for QHotkey::registered 88 | void registeredChanged(bool registered); 89 | 90 | private: 91 | Qt::Key _keyCode; 92 | Qt::KeyboardModifiers _modifiers; 93 | 94 | NativeShortcut _nativeShortcut; 95 | bool _registered; 96 | }; 97 | 98 | uint qHash(const QHotkey::NativeShortcut &key); 99 | uint qHash(const QHotkey::NativeShortcut &key, uint seed); 100 | 101 | Q_DECLARE_LOGGING_CATEGORY(logQHotkey) 102 | 103 | #endif // QHOTKEY_H 104 | -------------------------------------------------------------------------------- /QHotkey/qhotkey.pri: -------------------------------------------------------------------------------- 1 | message(The pri file has been moved one directory up! use that one instead) 2 | -------------------------------------------------------------------------------- /QHotkey/qhotkey_mac.cpp: -------------------------------------------------------------------------------- 1 | #include "qhotkey.h" 2 | #include "qhotkey_p.h" 3 | #include 4 | #include 5 | 6 | class QHotkeyPrivateMac : public QHotkeyPrivate 7 | { 8 | public: 9 | // QAbstractNativeEventFilter interface 10 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE; 11 | 12 | static OSStatus hotkeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void* data); 13 | 14 | protected: 15 | // QHotkeyPrivate interface 16 | quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE; 17 | quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; 18 | bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 19 | bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 20 | 21 | private: 22 | static bool isHotkeyHandlerRegistered; 23 | static QHash hotkeyRefs; 24 | }; 25 | NATIVE_INSTANCE(QHotkeyPrivateMac) 26 | 27 | bool QHotkeyPrivateMac::isHotkeyHandlerRegistered = false; 28 | QHash QHotkeyPrivateMac::hotkeyRefs; 29 | 30 | bool QHotkeyPrivateMac::nativeEventFilter(const QByteArray &eventType, void *message, long *result) 31 | { 32 | Q_UNUSED(eventType); 33 | Q_UNUSED(message); 34 | Q_UNUSED(result); 35 | return false; 36 | } 37 | 38 | quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode) 39 | { 40 | // Constants found in NSEvent.h from AppKit.framework 41 | switch (keycode) { 42 | case Qt::Key_Return: 43 | return kVK_Return; 44 | case Qt::Key_Enter: 45 | return kVK_ANSI_KeypadEnter; 46 | case Qt::Key_Tab: 47 | return kVK_Tab; 48 | case Qt::Key_Space: 49 | return kVK_Space; 50 | case Qt::Key_Backspace: 51 | return kVK_Delete; 52 | case Qt::Key_Escape: 53 | return kVK_Escape; 54 | case Qt::Key_CapsLock: 55 | return kVK_CapsLock; 56 | case Qt::Key_Option: 57 | return kVK_Option; 58 | case Qt::Key_F17: 59 | return kVK_F17; 60 | case Qt::Key_VolumeUp: 61 | return kVK_VolumeUp; 62 | case Qt::Key_VolumeDown: 63 | return kVK_VolumeDown; 64 | case Qt::Key_F18: 65 | return kVK_F18; 66 | case Qt::Key_F19: 67 | return kVK_F19; 68 | case Qt::Key_F20: 69 | return kVK_F20; 70 | case Qt::Key_F5: 71 | return kVK_F5; 72 | case Qt::Key_F6: 73 | return kVK_F6; 74 | case Qt::Key_F7: 75 | return kVK_F7; 76 | case Qt::Key_F3: 77 | return kVK_F3; 78 | case Qt::Key_F8: 79 | return kVK_F8; 80 | case Qt::Key_F9: 81 | return kVK_F9; 82 | case Qt::Key_F11: 83 | return kVK_F11; 84 | case Qt::Key_F13: 85 | return kVK_F13; 86 | case Qt::Key_F16: 87 | return kVK_F16; 88 | case Qt::Key_F14: 89 | return kVK_F14; 90 | case Qt::Key_F10: 91 | return kVK_F10; 92 | case Qt::Key_F12: 93 | return kVK_F12; 94 | case Qt::Key_F15: 95 | return kVK_F15; 96 | case Qt::Key_Help: 97 | return kVK_Help; 98 | case Qt::Key_Home: 99 | return kVK_Home; 100 | case Qt::Key_PageUp: 101 | return kVK_PageUp; 102 | case Qt::Key_Delete: 103 | return kVK_ForwardDelete; 104 | case Qt::Key_F4: 105 | return kVK_F4; 106 | case Qt::Key_End: 107 | return kVK_End; 108 | case Qt::Key_F2: 109 | return kVK_F2; 110 | case Qt::Key_PageDown: 111 | return kVK_PageDown; 112 | case Qt::Key_F1: 113 | return kVK_F1; 114 | case Qt::Key_Left: 115 | return kVK_LeftArrow; 116 | case Qt::Key_Right: 117 | return kVK_RightArrow; 118 | case Qt::Key_Down: 119 | return kVK_DownArrow; 120 | case Qt::Key_Up: 121 | return kVK_UpArrow; 122 | default: 123 | ; 124 | } 125 | 126 | UTF16Char ch = keycode; 127 | 128 | CFDataRef currentLayoutData; 129 | TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource(); 130 | 131 | if (currentKeyboard == NULL) 132 | return 0; 133 | 134 | currentLayoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData); 135 | CFRelease(currentKeyboard); 136 | if (currentLayoutData == NULL) 137 | return 0; 138 | 139 | UCKeyboardLayout* header = (UCKeyboardLayout*)CFDataGetBytePtr(currentLayoutData); 140 | UCKeyboardTypeHeader* table = header->keyboardTypeList; 141 | 142 | uint8_t *data = (uint8_t*)header; 143 | for (quint32 i=0; i < header->keyboardTypeCount; i++) { 144 | UCKeyStateRecordsIndex* stateRec = 0; 145 | if (table[i].keyStateRecordsIndexOffset != 0) { 146 | stateRec = reinterpret_cast(data + table[i].keyStateRecordsIndexOffset); 147 | if (stateRec->keyStateRecordsIndexFormat != kUCKeyStateRecordsIndexFormat) stateRec = 0; 148 | } 149 | 150 | UCKeyToCharTableIndex* charTable = reinterpret_cast(data + table[i].keyToCharTableIndexOffset); 151 | if (charTable->keyToCharTableIndexFormat != kUCKeyToCharTableIndexFormat) continue; 152 | 153 | for (quint32 j=0; j < charTable->keyToCharTableCount; j++) { 154 | UCKeyOutput* keyToChar = reinterpret_cast(data + charTable->keyToCharTableOffsets[j]); 155 | for (quint32 k=0; k < charTable->keyToCharTableSize; k++) { 156 | if (keyToChar[k] & kUCKeyOutputTestForIndexMask) { 157 | long idx = keyToChar[k] & kUCKeyOutputGetIndexMask; 158 | if (stateRec && idx < stateRec->keyStateRecordCount) { 159 | UCKeyStateRecord* rec = reinterpret_cast(data + stateRec->keyStateRecordOffsets[idx]); 160 | if (rec->stateZeroCharData == ch) return k; 161 | } 162 | } 163 | else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) { 164 | if (keyToChar[k] == ch) return k; 165 | } 166 | } 167 | } 168 | } 169 | return 0; 170 | } 171 | 172 | quint32 QHotkeyPrivateMac::nativeModifiers(Qt::KeyboardModifiers modifiers) 173 | { 174 | quint32 nMods = 0; 175 | if (modifiers & Qt::ShiftModifier) 176 | nMods |= shiftKey; 177 | if (modifiers & Qt::ControlModifier) 178 | nMods |= cmdKey; 179 | if (modifiers & Qt::AltModifier) 180 | nMods |= optionKey; 181 | if (modifiers & Qt::MetaModifier) 182 | nMods |= controlKey; 183 | if (modifiers & Qt::KeypadModifier) 184 | nMods |= kEventKeyModifierNumLockMask; 185 | return nMods; 186 | } 187 | 188 | bool QHotkeyPrivateMac::registerShortcut(QHotkey::NativeShortcut shortcut) 189 | { 190 | if (!this->isHotkeyHandlerRegistered) 191 | { 192 | EventTypeSpec eventSpec; 193 | eventSpec.eventClass = kEventClassKeyboard; 194 | eventSpec.eventKind = kEventHotKeyPressed; 195 | InstallApplicationEventHandler(&QHotkeyPrivateMac::hotkeyEventHandler, 1, &eventSpec, NULL, NULL); 196 | } 197 | 198 | EventHotKeyID hkeyID; 199 | hkeyID.signature = shortcut.key; 200 | hkeyID.id = shortcut.modifier; 201 | 202 | EventHotKeyRef eventRef = 0; 203 | OSStatus status = RegisterEventHotKey(shortcut.key, 204 | shortcut.modifier, 205 | hkeyID, 206 | GetApplicationEventTarget(), 207 | 0, 208 | &eventRef); 209 | if (status != noErr) { 210 | qCWarning(logQHotkey) << "Failed to register hotkey. Error:" 211 | << status; 212 | return false; 213 | } else { 214 | this->hotkeyRefs.insert(shortcut, eventRef); 215 | return true; 216 | } 217 | } 218 | 219 | bool QHotkeyPrivateMac::unregisterShortcut(QHotkey::NativeShortcut shortcut) 220 | { 221 | EventHotKeyRef eventRef = QHotkeyPrivateMac::hotkeyRefs.value(shortcut); 222 | OSStatus status = UnregisterEventHotKey(eventRef); 223 | if (status != noErr) { 224 | qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" 225 | << status; 226 | return false; 227 | } else { 228 | this->hotkeyRefs.remove(shortcut); 229 | return true; 230 | } 231 | } 232 | 233 | OSStatus QHotkeyPrivateMac::hotkeyEventHandler(EventHandlerCallRef nextHandler, EventRef event, void* data) 234 | { 235 | Q_UNUSED(nextHandler); 236 | Q_UNUSED(data); 237 | 238 | if (GetEventClass(event) == kEventClassKeyboard && 239 | GetEventKind(event) == kEventHotKeyPressed) { 240 | EventHotKeyID hkeyID; 241 | GetEventParameter(event, 242 | kEventParamDirectObject, 243 | typeEventHotKeyID, 244 | NULL, 245 | sizeof(EventHotKeyID), 246 | NULL, 247 | &hkeyID); 248 | hotkeyPrivate->activateShortcut({hkeyID.signature, hkeyID.id}); 249 | } 250 | 251 | return noErr; 252 | } 253 | -------------------------------------------------------------------------------- /QHotkey/qhotkey_p.h: -------------------------------------------------------------------------------- 1 | #ifndef QHOTKEY_P_H 2 | #define QHOTKEY_P_H 3 | 4 | #include "qhotkey.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class QHotkeyPrivate : public QObject, public QAbstractNativeEventFilter 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | QHotkeyPrivate();//singleton!!! 16 | ~QHotkeyPrivate(); 17 | 18 | static QHotkeyPrivate *instance(); 19 | 20 | QHotkey::NativeShortcut nativeShortcut(Qt::Key keycode, Qt::KeyboardModifiers modifiers); 21 | 22 | bool addShortcut(QHotkey *hotkey); 23 | bool removeShortcut(QHotkey *hotkey); 24 | 25 | protected: 26 | void activateShortcut(QHotkey::NativeShortcut shortcut); 27 | 28 | virtual quint32 nativeKeycode(Qt::Key keycode) = 0;//platform implement 29 | virtual quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) = 0;//platform implement 30 | 31 | virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement 32 | virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement 33 | 34 | private: 35 | QMultiHash shortcuts; 36 | 37 | Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey); 38 | Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey); 39 | Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers); 40 | }; 41 | 42 | #define NATIVE_INSTANCE(ClassName) \ 43 | Q_GLOBAL_STATIC(ClassName, hotkeyPrivate) \ 44 | \ 45 | QHotkeyPrivate *QHotkeyPrivate::instance()\ 46 | {\ 47 | return hotkeyPrivate;\ 48 | } 49 | 50 | #endif // QHOTKEY_P_H 51 | -------------------------------------------------------------------------------- /QHotkey/qhotkey_win.cpp: -------------------------------------------------------------------------------- 1 | #include "qhotkey.h" 2 | #include "qhotkey_p.h" 3 | #include 4 | #include 5 | 6 | #define HKEY_ID(nativeShortcut) (((nativeShortcut.key ^ (nativeShortcut.modifier << 8)) & 0x0FFF) | 0x7000) 7 | 8 | class QHotkeyPrivateWin : public QHotkeyPrivate 9 | { 10 | public: 11 | // QAbstractNativeEventFilter interface 12 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE; 13 | 14 | protected: 15 | // QHotkeyPrivate interface 16 | quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE; 17 | quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; 18 | bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 19 | bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 20 | 21 | private: 22 | static QString formatWinError(DWORD winError); 23 | }; 24 | NATIVE_INSTANCE(QHotkeyPrivateWin) 25 | 26 | bool QHotkeyPrivateWin::nativeEventFilter(const QByteArray &eventType, void *message, long *result) 27 | { 28 | Q_UNUSED(eventType); 29 | Q_UNUSED(result); 30 | 31 | MSG* msg = static_cast(message); 32 | if(msg->message == WM_HOTKEY) 33 | this->activateShortcut({HIWORD(msg->lParam), LOWORD(msg->lParam)}); 34 | 35 | return false; 36 | } 37 | 38 | quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode) 39 | { 40 | if(keycode <= 0xFFFF) {//Try to obtain the key from it's "character" 41 | const SHORT vKey = VkKeyScanW(keycode); 42 | if(vKey > -1) 43 | return LOBYTE(vKey); 44 | } 45 | 46 | //find key from switch/case --> Only finds a very small subset of keys 47 | switch (keycode) 48 | { 49 | case Qt::Key_Escape: 50 | return VK_ESCAPE; 51 | case Qt::Key_Tab: 52 | case Qt::Key_Backtab: 53 | return VK_TAB; 54 | case Qt::Key_Backspace: 55 | return VK_BACK; 56 | case Qt::Key_Return: 57 | case Qt::Key_Enter: 58 | return VK_RETURN; 59 | case Qt::Key_Insert: 60 | return VK_INSERT; 61 | case Qt::Key_Delete: 62 | return VK_DELETE; 63 | case Qt::Key_Pause: 64 | return VK_PAUSE; 65 | case Qt::Key_Print: 66 | return VK_PRINT; 67 | case Qt::Key_Clear: 68 | return VK_CLEAR; 69 | case Qt::Key_Home: 70 | return VK_HOME; 71 | case Qt::Key_End: 72 | return VK_END; 73 | case Qt::Key_Left: 74 | return VK_LEFT; 75 | case Qt::Key_Up: 76 | return VK_UP; 77 | case Qt::Key_Right: 78 | return VK_RIGHT; 79 | case Qt::Key_Down: 80 | return VK_DOWN; 81 | case Qt::Key_PageUp: 82 | return VK_PRIOR; 83 | case Qt::Key_PageDown: 84 | return VK_NEXT; 85 | case Qt::Key_CapsLock: 86 | return VK_CAPITAL; 87 | case Qt::Key_NumLock: 88 | return VK_NUMLOCK; 89 | case Qt::Key_ScrollLock: 90 | return VK_SCROLL; 91 | 92 | case Qt::Key_F1: 93 | return VK_F1; 94 | case Qt::Key_F2: 95 | return VK_F2; 96 | case Qt::Key_F3: 97 | return VK_F3; 98 | case Qt::Key_F4: 99 | return VK_F4; 100 | case Qt::Key_F5: 101 | return VK_F5; 102 | case Qt::Key_F6: 103 | return VK_F6; 104 | case Qt::Key_F7: 105 | return VK_F7; 106 | case Qt::Key_F8: 107 | return VK_F8; 108 | case Qt::Key_F9: 109 | return VK_F9; 110 | case Qt::Key_F10: 111 | return VK_F10; 112 | case Qt::Key_F11: 113 | return VK_F11; 114 | case Qt::Key_F12: 115 | return VK_F12; 116 | case Qt::Key_F13: 117 | return VK_F13; 118 | case Qt::Key_F14: 119 | return VK_F14; 120 | case Qt::Key_F15: 121 | return VK_F15; 122 | case Qt::Key_F16: 123 | return VK_F16; 124 | case Qt::Key_F17: 125 | return VK_F17; 126 | case Qt::Key_F18: 127 | return VK_F18; 128 | case Qt::Key_F19: 129 | return VK_F19; 130 | case Qt::Key_F20: 131 | return VK_F20; 132 | case Qt::Key_F21: 133 | return VK_F21; 134 | case Qt::Key_F22: 135 | return VK_F22; 136 | case Qt::Key_F23: 137 | return VK_F23; 138 | case Qt::Key_F24: 139 | return VK_F24; 140 | 141 | case Qt::Key_Menu: 142 | return VK_APPS; 143 | case Qt::Key_Help: 144 | return VK_HELP; 145 | case Qt::Key_MediaNext: 146 | return VK_MEDIA_NEXT_TRACK; 147 | case Qt::Key_MediaPrevious: 148 | return VK_MEDIA_PREV_TRACK; 149 | case Qt::Key_MediaPlay: 150 | return VK_MEDIA_PLAY_PAUSE; 151 | case Qt::Key_MediaStop: 152 | return VK_MEDIA_STOP; 153 | case Qt::Key_VolumeDown: 154 | return VK_VOLUME_DOWN; 155 | case Qt::Key_VolumeUp: 156 | return VK_VOLUME_UP; 157 | case Qt::Key_VolumeMute: 158 | return VK_VOLUME_MUTE; 159 | case Qt::Key_Mode_switch: 160 | return VK_MODECHANGE; 161 | case Qt::Key_Select: 162 | return VK_SELECT; 163 | case Qt::Key_Printer: 164 | return VK_PRINT; 165 | case Qt::Key_Execute: 166 | return VK_EXECUTE; 167 | case Qt::Key_Sleep: 168 | return VK_SLEEP; 169 | case Qt::Key_Period: 170 | return VK_DECIMAL; 171 | case Qt::Key_Play: 172 | return VK_PLAY; 173 | case Qt::Key_Cancel: 174 | return VK_CANCEL; 175 | 176 | case Qt::Key_Forward: 177 | return VK_BROWSER_FORWARD; 178 | case Qt::Key_Refresh: 179 | return VK_BROWSER_REFRESH; 180 | case Qt::Key_Stop: 181 | return VK_BROWSER_STOP; 182 | case Qt::Key_Search: 183 | return VK_BROWSER_SEARCH; 184 | case Qt::Key_Favorites: 185 | return VK_BROWSER_FAVORITES; 186 | case Qt::Key_HomePage: 187 | return VK_BROWSER_HOME; 188 | 189 | case Qt::Key_LaunchMail: 190 | return VK_LAUNCH_MAIL; 191 | case Qt::Key_LaunchMedia: 192 | return VK_LAUNCH_MEDIA_SELECT; 193 | case Qt::Key_Launch0: 194 | return VK_LAUNCH_APP1; 195 | case Qt::Key_Launch1: 196 | return VK_LAUNCH_APP2; 197 | 198 | case Qt::Key_Massyo: 199 | return VK_OEM_FJ_MASSHOU; 200 | case Qt::Key_Touroku: 201 | return VK_OEM_FJ_TOUROKU; 202 | 203 | default: 204 | return 0; 205 | } 206 | } 207 | 208 | quint32 QHotkeyPrivateWin::nativeModifiers(Qt::KeyboardModifiers modifiers) 209 | { 210 | quint32 nMods = 0; 211 | if (modifiers & Qt::ShiftModifier) 212 | nMods |= MOD_SHIFT; 213 | if (modifiers & Qt::ControlModifier) 214 | nMods |= MOD_CONTROL; 215 | if (modifiers & Qt::AltModifier) 216 | nMods |= MOD_ALT; 217 | if (modifiers & Qt::MetaModifier) 218 | nMods |= MOD_WIN; 219 | return nMods; 220 | } 221 | 222 | bool QHotkeyPrivateWin::registerShortcut(QHotkey::NativeShortcut shortcut) 223 | { 224 | BOOL ok = RegisterHotKey(NULL, 225 | HKEY_ID(shortcut), 226 | shortcut.modifier, 227 | shortcut.key); 228 | if(ok) 229 | return true; 230 | else { 231 | qCWarning(logQHotkey) << "Failed to register hotkey. Error:" 232 | << qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError())); 233 | return false; 234 | } 235 | } 236 | 237 | bool QHotkeyPrivateWin::unregisterShortcut(QHotkey::NativeShortcut shortcut) 238 | { 239 | BOOL ok = UnregisterHotKey(NULL, HKEY_ID(shortcut)); 240 | if(ok) 241 | return true; 242 | else { 243 | qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" 244 | << qPrintable(QHotkeyPrivateWin::formatWinError(::GetLastError())); 245 | return false; 246 | } 247 | } 248 | 249 | QString QHotkeyPrivateWin::formatWinError(DWORD winError) 250 | { 251 | wchar_t *buffer = NULL; 252 | DWORD num = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 253 | NULL, 254 | winError, 255 | 0, 256 | (LPWSTR)&buffer, 257 | 0, 258 | NULL); 259 | if(buffer) { 260 | QString res = QString::fromWCharArray(buffer, num); 261 | LocalFree(buffer); 262 | return res; 263 | } else 264 | return QString(); 265 | } 266 | -------------------------------------------------------------------------------- /QHotkey/qhotkey_x11.cpp: -------------------------------------------------------------------------------- 1 | #include "qhotkey.h" 2 | #include "qhotkey_p.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class QHotkeyPrivateX11 : public QHotkeyPrivate 10 | { 11 | public: 12 | // QAbstractNativeEventFilter interface 13 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE; 14 | 15 | protected: 16 | // QHotkeyPrivate interface 17 | quint32 nativeKeycode(Qt::Key keycode) Q_DECL_OVERRIDE; 18 | quint32 nativeModifiers(Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; 19 | bool registerShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 20 | bool unregisterShortcut(QHotkey::NativeShortcut shortcut) Q_DECL_OVERRIDE; 21 | 22 | private: 23 | static const QVector specialModifiers; 24 | static const quint32 validModsMask; 25 | 26 | static QString formatX11Error(Display *display, int errorCode); 27 | 28 | class HotkeyErrorHandler { 29 | public: 30 | HotkeyErrorHandler(); 31 | ~HotkeyErrorHandler(); 32 | 33 | static bool hasError; 34 | static QString errorString; 35 | 36 | private: 37 | XErrorHandler prevHandler; 38 | 39 | static int handleError(Display *display, XErrorEvent *error); 40 | }; 41 | }; 42 | NATIVE_INSTANCE(QHotkeyPrivateX11) 43 | 44 | const QVector QHotkeyPrivateX11::specialModifiers = {0, Mod2Mask, LockMask, (Mod2Mask | LockMask)}; 45 | const quint32 QHotkeyPrivateX11::validModsMask = ShiftMask | ControlMask | Mod1Mask | Mod4Mask; 46 | 47 | bool QHotkeyPrivateX11::nativeEventFilter(const QByteArray &eventType, void *message, long *result) 48 | { 49 | Q_UNUSED(eventType); 50 | Q_UNUSED(result); 51 | 52 | xcb_generic_event_t *genericEvent = static_cast(message); 53 | if (genericEvent->response_type == XCB_KEY_PRESS) { 54 | xcb_key_press_event_t *keyEvent = static_cast(message); 55 | this->activateShortcut({keyEvent->detail, keyEvent->state & QHotkeyPrivateX11::validModsMask}); 56 | } 57 | 58 | return false; 59 | } 60 | 61 | quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode) 62 | { 63 | KeySym keysym = XStringToKeysym(QKeySequence(keycode).toString(QKeySequence::NativeText).toLatin1().constData()); 64 | if (keysym == NoSymbol) { 65 | //not found -> just use the key 66 | if(keycode <= 0xFFFF) 67 | keysym = keycode; 68 | else 69 | return 0; 70 | } 71 | 72 | Display *display = QX11Info::display(); 73 | if(display) 74 | return XKeysymToKeycode(QX11Info::display(), keysym); 75 | else 76 | return 0; 77 | } 78 | 79 | quint32 QHotkeyPrivateX11::nativeModifiers(Qt::KeyboardModifiers modifiers) 80 | { 81 | quint32 nMods = 0; 82 | if (modifiers & Qt::ShiftModifier) 83 | nMods |= ShiftMask; 84 | if (modifiers & Qt::ControlModifier) 85 | nMods |= ControlMask; 86 | if (modifiers & Qt::AltModifier) 87 | nMods |= Mod1Mask; 88 | if (modifiers & Qt::MetaModifier) 89 | nMods |= Mod4Mask; 90 | return nMods; 91 | } 92 | 93 | bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut) 94 | { 95 | Display *display = QX11Info::display(); 96 | if(!display) 97 | return false; 98 | 99 | HotkeyErrorHandler errorHandler; 100 | for(quint32 specialMod : QHotkeyPrivateX11::specialModifiers) { 101 | XGrabKey(display, 102 | shortcut.key, 103 | shortcut.modifier | specialMod, 104 | DefaultRootWindow(display), 105 | True, 106 | GrabModeAsync, 107 | GrabModeAsync); 108 | } 109 | XSync(display, False); 110 | 111 | if(errorHandler.hasError) { 112 | qCWarning(logQHotkey) << "Failed to register hotkey. Error:" 113 | << qPrintable(errorHandler.errorString); 114 | this->unregisterShortcut(shortcut); 115 | return false; 116 | } else 117 | return true; 118 | } 119 | 120 | bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut) 121 | { 122 | Display *display = QX11Info::display(); 123 | if(!display) 124 | return false; 125 | 126 | HotkeyErrorHandler errorHandler; 127 | for(quint32 specialMod : QHotkeyPrivateX11::specialModifiers) { 128 | XUngrabKey(display, 129 | shortcut.key, 130 | shortcut.modifier | specialMod, 131 | DefaultRootWindow(display)); 132 | } 133 | XSync(display, False); 134 | 135 | if(errorHandler.hasError) { 136 | qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:" 137 | << qPrintable(errorHandler.errorString); 138 | return false; 139 | } else 140 | return true; 141 | } 142 | 143 | QString QHotkeyPrivateX11::formatX11Error(Display *display, int errorCode) 144 | { 145 | char errStr[256]; 146 | XGetErrorText(display, errorCode, errStr, 256); 147 | return QString::fromLatin1(errStr); 148 | } 149 | 150 | 151 | 152 | // ---------- QHotkeyPrivateX11::HotkeyErrorHandler implementation ---------- 153 | 154 | bool QHotkeyPrivateX11::HotkeyErrorHandler::hasError = false; 155 | QString QHotkeyPrivateX11::HotkeyErrorHandler::errorString; 156 | 157 | QHotkeyPrivateX11::HotkeyErrorHandler::HotkeyErrorHandler() 158 | { 159 | prevHandler = XSetErrorHandler(&HotkeyErrorHandler::handleError); 160 | } 161 | 162 | QHotkeyPrivateX11::HotkeyErrorHandler::~HotkeyErrorHandler() 163 | { 164 | XSetErrorHandler(prevHandler); 165 | hasError = false; 166 | errorString.clear(); 167 | } 168 | 169 | int QHotkeyPrivateX11::HotkeyErrorHandler::handleError(Display *display, XErrorEvent *error) 170 | { 171 | QT_WARNING_PUSH 172 | QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough") 173 | switch (error->error_code) { 174 | case BadAccess: 175 | case BadValue: 176 | case BadWindow: 177 | if (error->request_code == 33 || //grab key 178 | error->request_code == 34) {// ungrab key 179 | hasError = true; 180 | errorString = QHotkeyPrivateX11::formatX11Error(display, error->error_code); 181 | return 1; 182 | } 183 | default: 184 | return 0; 185 | } 186 | QT_WARNING_POP 187 | } 188 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # QBaiduFm 2 | A Online Music Player within Baidu FM(百度FM在线试听), 3 | 4 | 支持: 5 | 1.在线试听 6 | 2.多频道选择 7 | 3.用户登录 8 | 4.音乐下载, 9 | 5.快捷键 10 | 11 | 等特性,是学习Qt网络的入门资料... 12 | 13 | *** 14 | 15 | 暂时算是本人的star最多的项目了,按照惯例来几张图吧 16 | ubuntu下的 17 | ![Under Ubuntu](https://github.com/spygg/QBaiduFm/blob/master/screenshot/ubuntu.png "Ubuntu") 18 | 19 | win10下的 20 | ![Win10](https://github.com/spygg/QBaiduFm/blob/master/screenshot/win10.png "Win10") 21 | 22 | **还可以下载哦** 23 | ![下载](https://github.com/spygg/QBaiduFm/blob/master/screenshot/download.png "下载") 24 | 25 | 26 | 编译: 27 | 28 | 用Qt Creator 打开,直接编译好了(最好不要使用影子工程) 29 | 命令行 qmake & make 30 | 31 | 32 | 安装: 33 | 34 | 1. ubuntu下 35 | cd QBaiduFm 36 | sudo ./install.sh 37 | 38 | 2. Windows 下 39 | 无(直接运行exe好了) 40 | 41 | 42 | ps: 43 | 由于是一个玩具类型的小软件,主要是自己拿来在ubunut下使用.基本不会在更新了,考虑重新开一个坑,模仿大网易采用QML和C++混合编程,理论上支持几乎所有的操作系统(Android, ios, linux, windows). 敬请期待!!! 44 | 45 | 原理方面可以参见我的[CSDN博客](www.blog.csdn.net/spygg) 46 | -------------------------------------------------------------------------------- /aristpicture.cpp: -------------------------------------------------------------------------------- 1 | #include "aristpicture.h" 2 | #include "ui_aristpicture.h" 3 | #include "getcirclescaledpixmap.h" 4 | #include 5 | 6 | AristPicture::AristPicture(QWidget *parent) : 7 | QFrame(parent), 8 | ui(new Ui::AristPicture) 9 | { 10 | ui->setupUi(this); 11 | setFrameStyle(QFrame::NoFrame); 12 | 13 | 14 | m_timer = new QTimer(this); 15 | m_iCurrentRotateAngle = 0; 16 | m_mixedPic.load(":/img/cd.png"); 17 | 18 | connect(ui->label, SIGNAL(enterSignal()), this, SLOT(enterSlot())); 19 | connect(ui->label, SIGNAL(leaveSignal()), this, SLOT(leaveSlot())); 20 | connect(ui->label, SIGNAL(clickSignal()), this, SLOT(clickSlot())); 21 | connect(this, SIGNAL(showPicSignal(qint64)), this, SLOT(showwhirlPicSlot(qint64)) ); 22 | connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollInfo())); 23 | 24 | m_timer->setInterval(1000); 25 | m_timer->start(); 26 | 27 | m_iCurrentState = STATE_STOP; 28 | m_userName = "未知用户"; 29 | m_channelInfo = "空"; 30 | } 31 | 32 | AristPicture::~AristPicture() 33 | { 34 | delete ui; 35 | } 36 | 37 | void AristPicture::scrollInfo() 38 | { 39 | static int nPos = 0; 40 | static int iturn = 0; 41 | 42 | QString scrollStr; 43 | 44 | if(iturn) 45 | { 46 | scrollStr += QString("当前登录:"); 47 | scrollStr += m_userName; 48 | } 49 | else 50 | { 51 | scrollStr += "频道: "; 52 | scrollStr += m_channelInfo; 53 | } 54 | 55 | if (nPos > scrollStr.length()) 56 | { 57 | nPos = 0; 58 | 59 | iturn = ~iturn; 60 | } 61 | 62 | 63 | QString info = QString("

"); 64 | info += scrollStr.mid(nPos); 65 | info += QString("

"); 66 | 67 | ui->label_info->setText(info); 68 | nPos++; 69 | } 70 | 71 | void AristPicture::channelChangedSlot(QString channel) 72 | { 73 | m_channelInfo = channel; 74 | } 75 | 76 | void AristPicture::userLoninSlot(QString userInfo) 77 | { 78 | qDebug() << "用户" << userInfo; 79 | m_userName = userInfo; 80 | } 81 | 82 | void AristPicture::setDefultPic(qint64 totalTime) 83 | { 84 | m_iCurrentRotateAngle = 0; 85 | m_totalTime = totalTime; 86 | m_mixedPic.load(":/img/cd.png"); 87 | ui->label->setPixmap(m_mixedPic); 88 | } 89 | 90 | void AristPicture::enterSlot() 91 | { 92 | disconnect(this, SIGNAL(showPicSignal(qint64)), this, SLOT(showwhirlPicSlot(qint64)) ); 93 | 94 | if(m_iCurrentState == STATE_PALYING) 95 | { 96 | QPixmap pixmap; 97 | pixmap.load(":/img/pause.png"); 98 | 99 | QPixmap pixMix; 100 | 101 | GetCircleScaledPixmap destPic; 102 | 103 | pixMix = destPic.getCirclePictureAtCenter(pixmap, m_mixedCurrentPic, 85, 85);//290, 290 104 | 105 | ui->label->setPixmap(pixMix); 106 | 107 | } 108 | 109 | } 110 | 111 | void AristPicture::clickSlot() 112 | { 113 | if(m_iCurrentState == STATE_PALYING) 114 | { 115 | m_iCurrentState = STATE_PAUSE; 116 | emit pauseSignal(true); 117 | 118 | 119 | QPixmap pixmap; 120 | pixmap.load(":/img/play.png"); 121 | 122 | QPixmap pixMix; 123 | 124 | GetCircleScaledPixmap destPic; 125 | 126 | pixMix = destPic.getCirclePictureAtCenter(pixmap, m_mixedCurrentPic, 85, 85);//290, 290 127 | 128 | ui->label->setPixmap(pixMix); 129 | 130 | 131 | } 132 | else if(m_iCurrentState == STATE_PAUSE) 133 | { 134 | m_iCurrentState = STATE_PALYING; 135 | emit pauseSignal(false); 136 | 137 | QPixmap pixmap; 138 | pixmap.load(":/img/pause.png"); 139 | 140 | QPixmap pixMix; 141 | 142 | GetCircleScaledPixmap destPic; 143 | 144 | pixMix = destPic.getCirclePictureAtCenter(pixmap, m_mixedCurrentPic, 85, 85);//290, 290 145 | 146 | ui->label->setPixmap(pixMix); 147 | } 148 | } 149 | 150 | void AristPicture::leaveSlot() 151 | { 152 | if(STATE_PALYING == m_iCurrentState) 153 | { 154 | connect(this, SIGNAL(showPicSignal(qint64)), this, SLOT(showwhirlPicSlot(qint64)) ); 155 | } 156 | } 157 | 158 | void AristPicture::setAristPic(QPixmap pixmap) 159 | { 160 | QPixmap picBackGournd(":/img/cd.png"); 161 | GetCircleScaledPixmap destPic; 162 | 163 | m_mixedCurrentPic = m_mixedPic = destPic.getCirclePictureAtCenter(pixmap, picBackGournd);//290, 290 164 | 165 | if(STATE_PALYING != m_iCurrentState) 166 | { 167 | m_iCurrentState = STATE_PALYING; 168 | } 169 | } 170 | 171 | 172 | void AristPicture::positionChanged(qint64 position) 173 | { 174 | emit showPicSignal(position); 175 | } 176 | 177 | void AristPicture::showwhirlPicSlot(qint64 position) 178 | { 179 | m_iCurrentRotateAngle = position / (1.0 * m_totalTime) * 360; 180 | 181 | QTransform trs; 182 | trs.rotate(m_iCurrentRotateAngle); 183 | 184 | QPixmap pix; 185 | pix = m_mixedPic.transformed(trs)/*.scaled(QSize(240, 240), Qt::KeepAspectRatio, Qt::SmoothTransformation)*/; 186 | 187 | qreal fx = 0; 188 | qreal fy = 0; 189 | 190 | //qDebug() << pix.size().width() << m_mixedPic.size().width() << pix.size().height() << m_mixedPic.height(); 191 | 192 | fx = (pix.size().width() - m_mixedPic.size().width())/2.0; 193 | fy = (pix.size().height() - m_mixedPic.height())/2.0; 194 | pix = pix.copy(fx, fy, m_mixedPic.height(), m_mixedPic.height()); 195 | 196 | m_mixedCurrentPic = pix = pix.scaled(QSize(180, 180), Qt::KeepAspectRatio, Qt::SmoothTransformation); 197 | // qDebug() << pix.size().width() << m_mixedPic.size().width() << pix.size().height() << m_mixedPic.height(); 198 | ui->label->setPixmap(pix); 199 | } 200 | -------------------------------------------------------------------------------- /aristpicture.h: -------------------------------------------------------------------------------- 1 | #ifndef ARISTPICTURE_H 2 | #define ARISTPICTURE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "channelswidget.h" 9 | 10 | namespace Ui { 11 | class AristPicture; 12 | } 13 | 14 | enum PLAYER_STATE 15 | { 16 | STATE_STOP, 17 | STATE_PAUSE, 18 | STATE_PALYING 19 | }; 20 | 21 | class AristPicture : public QFrame 22 | { 23 | Q_OBJECT 24 | 25 | public: 26 | explicit AristPicture(QWidget *parent = 0); 27 | ~AristPicture(); 28 | 29 | private: 30 | Ui::AristPicture *ui; 31 | QPixmap m_mixedPic; 32 | QPixmap m_mixedCurrentPic; 33 | QTimer *m_timer; 34 | 35 | private: 36 | ushort m_iCurrentRotateAngle; 37 | int m_iCurrentState; 38 | qint64 m_totalTime; 39 | QString m_channelInfo; 40 | QString m_userName; 41 | 42 | public: 43 | void setAristPic(QPixmap pixmap); 44 | 45 | 46 | public slots: 47 | void setDefultPic(qint64 totalTime); 48 | void channelChangedSlot(QString channel); 49 | void userLoninSlot(QString userInfo); 50 | 51 | void scrollInfo(); 52 | private slots: 53 | void clickSlot(); 54 | void leaveSlot(); 55 | void enterSlot(); 56 | void positionChanged(qint64 position); 57 | void showwhirlPicSlot(qint64 position); 58 | signals: 59 | void pauseSignal(bool pause); 60 | void showPicSignal(qint64 position); 61 | 62 | }; 63 | 64 | #endif // ARISTPICTURE_H 65 | -------------------------------------------------------------------------------- /aristpicture.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | AristPicture 4 | 5 | 6 | 7 | 0 8 | 0 9 | 240 10 | 276 11 | 12 | 13 | 14 | Frame 15 | 16 | 17 | 1.000000000000000 18 | 19 | 20 | QFrame::StyledPanel 21 | 22 | 23 | QFrame::Raised 24 | 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 0 34 | 35 | 36 | 0 37 | 38 | 39 | 40 | 41 | 42 | 0 43 | 0 44 | 45 | 46 | 47 | 48 | 0 49 | 50 | 51 | 0 52 | 53 | 54 | 0 55 | 56 | 57 | 58 | 59 | 60 | 0 61 | 0 62 | 63 | 64 | 65 | <html><head/><body><p align="center">当前登录:<a href="http://www.baidu.com"><span style=" text-decoration: underline; color:#0000ff;">spygg</span></a> KTV推荐</p></body></html> 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 0 77 | 0 78 | 79 | 80 | 81 | 82 | 0 83 | 84 | 85 | 0 86 | 87 | 88 | 0 89 | 90 | 91 | 92 | 93 | 94 | 0 95 | 0 96 | 97 | 98 | 99 | 100 | 101 | 102 | true 103 | 104 | 105 | Qt::AlignCenter 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | EventLabel 117 | QLabel 118 |
eventlabel.h
119 |
120 |
121 | 122 | 123 |
124 | -------------------------------------------------------------------------------- /baiduFmUi.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-12-19T08:27:14 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network multimedia 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = QBaiduFm 12 | TEMPLATE = app 13 | 14 | CONFIG += c++11 15 | 16 | include(./qhotkey.pri) 17 | 18 | SOURCES += main.cpp\ 19 | widget.cpp \ 20 | aristpicture.cpp \ 21 | lyrics.cpp \ 22 | channelswidget.cpp \ 23 | logindlg.cpp \ 24 | volpannel.cpp \ 25 | getbaiduchannel.cpp \ 26 | getsongplaylistid.cpp \ 27 | getsongreallink.cpp \ 28 | getaristpic.cpp \ 29 | getlrc.cpp \ 30 | getcirclescaledpixmap.cpp \ 31 | eventlabel.cpp \ 32 | downloadfile.cpp 33 | 34 | 35 | HEADERS += widget.h \ 36 | aristpicture.h \ 37 | lyrics.h \ 38 | channelswidget.h \ 39 | logindlg.h \ 40 | volpannel.h \ 41 | getbaiduchannel.h \ 42 | getsongplaylistid.h \ 43 | getsongreallink.h \ 44 | getaristpic.h \ 45 | getlrc.h \ 46 | getcirclescaledpixmap.h \ 47 | eventlabel.h \ 48 | downloadfile.h 49 | 50 | 51 | FORMS += widget.ui \ 52 | aristpicture.ui \ 53 | lyrics.ui \ 54 | channelswidget.ui \ 55 | logindlg.ui 56 | 57 | RESOURCES += \ 58 | img.qrc 59 | -------------------------------------------------------------------------------- /channelswidget.cpp: -------------------------------------------------------------------------------- 1 | #include "channelswidget.h" 2 | #include "ui_channelswidget.h" 3 | #include 4 | #include 5 | 6 | ChannelsWidget::ChannelsWidget(QWidget *parent, QNetworkCookieJar *cookJar) : 7 | QFrame(parent), 8 | ui(new Ui::ChannelsWidget) 9 | { 10 | ui->setupUi(this); 11 | setFrameStyle(QFrame::NoFrame); 12 | 13 | m_getChannelList = new GetBaiduChannel(0, cookJar); 14 | m_gridlayOut = new QGridLayout; 15 | 16 | m_channelList = getChannelList(); 17 | 18 | for(int i = 0, k = 0; i < m_channelList.size() / 4; i++, k += 4) 19 | { 20 | for(int j = 0; j < 4; j++) 21 | { 22 | QPushButton *btn = new QPushButton(this); 23 | 24 | btn->setText(m_channelList.at(k + j).channelName); 25 | //qDebug() << m_channelList.at(k + j).channelName; 26 | m_gridlayOut->addWidget(btn, i, j); 27 | //qDebug() << k + j; 28 | m_btnGroup.addButton(btn, k + j); 29 | } 30 | } 31 | 32 | setLayout(m_gridlayOut); 33 | 34 | connect( &m_btnGroup, SIGNAL(buttonClicked (int)), this, SLOT(channelSelected(int)) ); 35 | m_iLastChannelIndex = 0; 36 | } 37 | 38 | void ChannelsWidget::channelSelected(int iChannel) 39 | { 40 | //先还原样式表 41 | m_btnGroup.button(m_iLastChannelIndex)->setStyleSheet(""); 42 | 43 | m_btnGroup.button(iChannel)->setStyleSheet("QPushButton{ font-weight:600;color:#5500ff;}"); 44 | m_iLastChannelIndex = iChannel; 45 | emit channelChanged(m_channelList.at(iChannel)); 46 | 47 | //记录当前频道信息 48 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm"); 49 | settings.beginGroup("User"); 50 | settings.setValue("ChannelId", m_channelList.at(iChannel).channelId); 51 | settings.setValue("ChannelName", m_channelList.at(iChannel).channelName); 52 | settings.setValue("ChannelIndex", iChannel); 53 | settings.endGroup(); 54 | } 55 | 56 | 57 | ChannelsWidget::~ChannelsWidget() 58 | { 59 | delete ui; 60 | } 61 | 62 | void ChannelsWidget::leaveEvent(QEvent *event) 63 | { 64 | hide(); 65 | } 66 | 67 | QList ChannelsWidget::getChannelList() 68 | { 69 | return m_getChannelList->getMusicChannel(); 70 | } 71 | -------------------------------------------------------------------------------- /channelswidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CHANNELSWIDGET_H 2 | #define CHANNELSWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | #include "getbaiduchannel.h" 8 | 9 | namespace Ui { 10 | class ChannelsWidget; 11 | } 12 | 13 | class ChannelsWidget : public QFrame 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit ChannelsWidget(QWidget *parent = 0, QNetworkCookieJar *cookJar = NULL); 19 | ~ChannelsWidget(); 20 | 21 | QList getChannelList(); 22 | private: 23 | GetBaiduChannel *m_getChannelList; 24 | Ui::ChannelsWidget *ui; 25 | void leaveEvent(QEvent *event); 26 | 27 | QGridLayout *m_gridlayOut; 28 | QButtonGroup m_btnGroup; 29 | 30 | QList m_channelList; 31 | int m_iLastChannelIndex; 32 | 33 | public slots: 34 | void channelSelected(int iChannel); 35 | 36 | signals: 37 | void channelChanged(CHANNEL_INFO Channel); 38 | }; 39 | 40 | #endif // CHANNELSWIDGET_H 41 | -------------------------------------------------------------------------------- /channelswidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ChannelsWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 434 10 | 498 11 | 12 | 13 | 14 | Frame 15 | 16 | 17 | QFrame::StyledPanel 18 | 19 | 20 | QFrame::Raised 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /download/爱的初体验.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/download/爱的初体验.mp3 -------------------------------------------------------------------------------- /downloadfile.cpp: -------------------------------------------------------------------------------- 1 | #include "downloadfile.h" 2 | 3 | DownLoadFile::DownLoadFile(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void DownLoadFile::getMp3File(QString fileName, QString url) 9 | { 10 | QNetworkRequest networkRequest; 11 | QNetworkAccessManager networkManager; 12 | 13 | networkRequest.setUrl(QUrl(url)); 14 | qDebug() << url; 15 | 16 | QNetworkReply *reply = networkManager.get(networkRequest); 17 | 18 | QEventLoop loop; 19 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 20 | loop.exec(); 21 | reply->deleteLater(); 22 | 23 | QFile file; 24 | file.setFileName(fileName); 25 | bool bOk = file.open(QIODevice::WriteOnly); 26 | if(bOk) 27 | { 28 | file.write(reply->readAll()); 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /downloadfile.h: -------------------------------------------------------------------------------- 1 | #ifndef DOWNLOADFILE_H 2 | #define DOWNLOADFILE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class DownLoadFile: public QObject 14 | { 15 | Q_OBJECT 16 | public: 17 | explicit DownLoadFile(QObject *parent = 0); 18 | 19 | public: 20 | void getMp3File(QString fileName, QString url); 21 | }; 22 | 23 | #endif // DOWNLOADFILE_H 24 | -------------------------------------------------------------------------------- /eventlabel.cpp: -------------------------------------------------------------------------------- 1 | #include "eventlabel.h" 2 | #include 3 | #include 4 | 5 | EventLabel::EventLabel(QWidget *parent):QLabel(parent) 6 | { 7 | 8 | } 9 | 10 | EventLabel::~EventLabel() 11 | { 12 | 13 | } 14 | 15 | void EventLabel::enterEvent(QEvent *) 16 | { 17 | emit enterSignal(); 18 | } 19 | 20 | void EventLabel::mousePressEvent(QMouseEvent * ev) 21 | { 22 | emit clickSignal(); 23 | } 24 | 25 | 26 | void EventLabel::leaveEvent(QEvent *) 27 | { 28 | emit leaveSignal(); 29 | } 30 | -------------------------------------------------------------------------------- /eventlabel.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTLABEL_H 2 | #define EVENTLABEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class EventLabel : public QLabel 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | explicit EventLabel(QWidget *parent = 0); 14 | ~EventLabel(); 15 | 16 | private: 17 | void enterEvent(QEvent*); 18 | void leaveEvent(QEvent*); 19 | void mousePressEvent(QMouseEvent * ev); 20 | 21 | signals: 22 | void enterSignal(); 23 | void leaveSignal(); 24 | void clickSignal(); 25 | }; 26 | 27 | #endif // EVENTLABEL_H 28 | -------------------------------------------------------------------------------- /getaristpic.cpp: -------------------------------------------------------------------------------- 1 | #include "getaristpic.h" 2 | 3 | GetAristPic::GetAristPic(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | QPixmap GetAristPic::getAristPic(QString url) 9 | { 10 | QNetworkRequest networkRequest; 11 | QNetworkAccessManager networkManager; 12 | 13 | networkRequest.setUrl(QUrl(url)); 14 | 15 | QNetworkReply *reply = networkManager.get(networkRequest); 16 | 17 | QEventLoop loop; 18 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 19 | loop.exec(); 20 | reply->deleteLater(); 21 | 22 | 23 | QPixmap pic; 24 | pic.loadFromData(reply->readAll()); 25 | 26 | return pic; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /getaristpic.h: -------------------------------------------------------------------------------- 1 | #ifndef GETARISTPIC_H 2 | #define GETARISTPIC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | class GetAristPic : public QObject 16 | { 17 | Q_OBJECT 18 | public: 19 | explicit GetAristPic(QObject *parent = 0); 20 | 21 | signals: 22 | 23 | public slots: 24 | 25 | 26 | public: 27 | QPixmap getAristPic(QString url); 28 | }; 29 | 30 | #endif // GETARISTPIC_H 31 | -------------------------------------------------------------------------------- /getbaiduchannel.cpp: -------------------------------------------------------------------------------- 1 | #include "getbaiduchannel.h" 2 | 3 | const QString channelUrl = "http://fm.baidu.com/dev/api/?tn=channellist"; 4 | 5 | GetBaiduChannel::GetBaiduChannel(QFrame *parent, QNetworkCookieJar *cookie) : QFrame(parent) 6 | { 7 | m_cookJar = cookie; 8 | } 9 | 10 | QList GetBaiduChannel::getMusicChannel() 11 | { 12 | QList channelInfoList; 13 | 14 | QNetworkRequest networkRequest; 15 | QNetworkAccessManager *networkManager = new QNetworkAccessManager; 16 | 17 | networkRequest.setUrl(QUrl(channelUrl)); 18 | 19 | networkManager->setCookieJar(m_cookJar); 20 | QNetworkReply *reply = networkManager->get(networkRequest); 21 | 22 | QEventLoop loop; 23 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 24 | loop.exec(); 25 | reply->deleteLater(); 26 | 27 | QByteArray buf = reply->readAll(); 28 | 29 | //qDebug() << buf; 30 | 31 | QJsonParseError jsonError; 32 | QJsonDocument jsonRes = QJsonDocument::fromJson(buf, &jsonError);; 33 | 34 | if(jsonError.error == QJsonParseError::NoError) 35 | { 36 | if(jsonRes.isObject()) 37 | { 38 | QVariantMap result = jsonRes.toVariant().toMap(); 39 | 40 | foreach(QVariant channel, result["channel_list"].toList()) 41 | { 42 | QVariantMap channelMap = channel.toMap(); 43 | 44 | 45 | CHANNEL_INFO channelInfo; 46 | channelInfo.channelId = channelMap["channel_id"].toString(); 47 | channelInfo.channelName = channelMap["channel_name"].toString(); 48 | 49 | channelInfoList.append(channelInfo); 50 | 51 | } 52 | } 53 | } 54 | 55 | return channelInfoList; 56 | } 57 | -------------------------------------------------------------------------------- /getbaiduchannel.h: -------------------------------------------------------------------------------- 1 | #ifndef GETBAIDUCHANNEL_H 2 | #define GETBAIDUCHANNEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct _CHANNEL_INFO 17 | { 18 | QString channelId; 19 | QString channelName; 20 | }CHANNEL_INFO; 21 | 22 | class GetBaiduChannel : public QFrame 23 | { 24 | Q_OBJECT 25 | 26 | public: 27 | explicit GetBaiduChannel(QFrame *parent = 0, QNetworkCookieJar *cookie = NULL); 28 | 29 | signals: 30 | 31 | public slots: 32 | 33 | public: 34 | QList getMusicChannel(); 35 | 36 | private: 37 | QNetworkCookieJar *m_cookJar; 38 | }; 39 | 40 | #endif // GETBAIDUCHANNEL_H 41 | -------------------------------------------------------------------------------- /getcirclescaledpixmap.cpp: -------------------------------------------------------------------------------- 1 | #include "getcirclescaledpixmap.h" 2 | #include 3 | 4 | GetCircleScaledPixmap::GetCircleScaledPixmap(QObject *parent) : QObject(parent) 5 | { 6 | 7 | } 8 | 9 | 10 | QPixmap GetCircleScaledPixmap::getCirclePictureAtCenter(QPixmap srcPic, QPixmap backPic, int width, int height) 11 | { 12 | int iCenterX = 0; 13 | int iCenterY = 0; 14 | 15 | // width = srcPic.width() - 10; 16 | // height = srcPic.height() - 10 ; 17 | 18 | iCenterX = (srcPic.width() - width) / 2.0 - 39; 19 | iCenterY = (srcPic.height() - height) / 2.0 - 39; 20 | 21 | //在backPic上画源图片 22 | QPainter paint(&backPic); 23 | QRegion region(iCenterX, iCenterY, width, height, QRegion::Ellipse); 24 | paint.setClipRegion(region); 25 | 26 | paint.drawPixmap(iCenterX, iCenterY, width, height, srcPic); 27 | 28 | return backPic; 29 | } 30 | 31 | 32 | QPixmap GetCircleScaledPixmap::getCirclePictureAtCenter(QPixmap srcPic, QPixmap backPic) 33 | { 34 | int iCenterX = 0; 35 | int iCenterY = 0; 36 | int width = 0; 37 | int height = 0; 38 | 39 | width = srcPic.width() - 10; 40 | height = srcPic.height() - 10 ; 41 | 42 | iCenterX = (srcPic.width() - width) / 2.0; 43 | iCenterY = (srcPic.height() - height) / 2.0; 44 | 45 | //在backPic上画源图片 46 | QPainter paint(&backPic); 47 | QRegion region(iCenterX, iCenterY, width, height, QRegion::Ellipse); 48 | paint.setClipRegion(region); 49 | 50 | paint.drawPixmap(iCenterX, iCenterY, width, height, srcPic); 51 | 52 | return backPic; 53 | } 54 | -------------------------------------------------------------------------------- /getcirclescaledpixmap.h: -------------------------------------------------------------------------------- 1 | #ifndef GETCIRCLESCALEDPIXMAP_H 2 | #define GETCIRCLESCALEDPIXMAP_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | class GetCircleScaledPixmap : public QObject 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit GetCircleScaledPixmap(QObject *parent = 0); 15 | 16 | signals: 17 | 18 | public slots: 19 | 20 | public: 21 | 22 | QPixmap getCirclePictureAtCenter(QPixmap srcPic, QPixmap backPic/*, int width, int height*/); 23 | QPixmap getCirclePictureAtCenter(QPixmap srcPic, QPixmap backPic, int width, int height); 24 | }; 25 | 26 | #endif // GETCIRCLESCALEDPIXMAP_H 27 | -------------------------------------------------------------------------------- /getlrc.cpp: -------------------------------------------------------------------------------- 1 | #include "getlrc.h" 2 | 3 | GetLrc::GetLrc(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | QString GetLrc::getLrc(QString url) 9 | { 10 | QNetworkRequest networkRequest; 11 | QNetworkAccessManager networkManager; 12 | 13 | qDebug() << url; 14 | //url = "http://musicdata.baidu.com" + url; 15 | networkRequest.setUrl(QUrl(url)); 16 | 17 | QNetworkReply *reply = networkManager.get(networkRequest); 18 | 19 | QEventLoop loop; 20 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 21 | loop.exec(); 22 | reply->deleteLater(); 23 | 24 | QString lrc; 25 | lrc = reply->readAll(); 26 | 27 | return lrc; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /getlrc.h: -------------------------------------------------------------------------------- 1 | #ifndef GETLRC_H 2 | #define GETLRC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class GetLrc : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit GetLrc(QObject *parent = 0); 19 | 20 | public: 21 | QString getLrc(QString url); 22 | }; 23 | 24 | #endif // GETARISTPIC_H 25 | -------------------------------------------------------------------------------- /getsongplaylistid.cpp: -------------------------------------------------------------------------------- 1 | #include "getsongplaylistid.h" 2 | 3 | const QString playListUrl = "http://fm.baidu.com/dev/api/?tn=playlist&format=json&id="; 4 | 5 | GetSongPlayListId::GetSongPlayListId(QObject *parent, QNetworkCookieJar *cookie) : QObject(parent) 6 | { 7 | m_cookJar = cookie; 8 | } 9 | 10 | QList GetSongPlayListId::getSongIdList(QString channelId) 11 | { 12 | QNetworkRequest networkRequest; 13 | QNetworkAccessManager *networkManager = new QNetworkAccessManager; 14 | 15 | networkRequest.setUrl(QUrl(playListUrl + channelId)); 16 | 17 | networkManager->setCookieJar(m_cookJar); 18 | 19 | QNetworkReply *reply = networkManager->get(networkRequest); 20 | 21 | QEventLoop loop; 22 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 23 | loop.exec(); 24 | reply->deleteLater(); 25 | 26 | QList songId; 27 | QByteArray buf = reply->readAll(); 28 | 29 | QJsonParseError jsonError; 30 | QJsonDocument jsonRes = QJsonDocument::fromJson(buf, &jsonError);; 31 | 32 | if(jsonError.error == QJsonParseError::NoError) 33 | { 34 | if(jsonRes.isObject()) 35 | { 36 | QVariantMap result = jsonRes.toVariant().toMap(); 37 | 38 | foreach(QVariant song, result["list"].toList()) 39 | { 40 | QVariantMap songMap = song.toMap(); 41 | QString id = songMap["id"].toString(); 42 | 43 | //如果歌曲ID有效 44 | if(!id.isEmpty()) 45 | { 46 | songId.append(id); 47 | } 48 | 49 | } 50 | } 51 | } 52 | 53 | // qDebug() << buf; 54 | 55 | return songId; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /getsongplaylistid.h: -------------------------------------------------------------------------------- 1 | #ifndef GETSONGPLAYLISTID_H 2 | #define GETSONGPLAYLISTID_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | class GetSongPlayListId : public QObject 15 | { 16 | Q_OBJECT 17 | public: 18 | explicit GetSongPlayListId(QObject *parent = 0, QNetworkCookieJar *cookie = NULL); 19 | 20 | signals: 21 | 22 | public slots: 23 | 24 | public: 25 | QList getSongIdList(QString channelId); 26 | 27 | 28 | private: 29 | QNetworkCookieJar *m_cookJar; 30 | }; 31 | 32 | #endif // GETSONGPLAYLISTID_H 33 | -------------------------------------------------------------------------------- /getsongreallink.cpp: -------------------------------------------------------------------------------- 1 | #include "getsongreallink.h" 2 | 3 | const QString downLoadLinkUrl = "http://music.baidu.com/data/music/fmlink?type=mp3&rate=320&songIds="; 4 | 5 | GetSongRealLink::GetSongRealLink(QObject *parent, QNetworkCookieJar *cookie) : QObject(parent) 6 | { 7 | m_cookJar = cookie; 8 | } 9 | 10 | SONG_INFO GetSongRealLink::getSongRealLinkById(QString songId) 11 | { 12 | QNetworkRequest networkRequest; 13 | QNetworkAccessManager networkManager; 14 | 15 | networkRequest.setUrl(QUrl(downLoadLinkUrl + songId)); 16 | networkManager.setCookieJar(m_cookJar); 17 | 18 | QNetworkReply *reply = networkManager.get(networkRequest); 19 | 20 | QEventLoop loop; 21 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 22 | loop.exec(); 23 | reply->deleteLater(); 24 | 25 | //歌曲信息 26 | SONG_INFO songInfo; 27 | QByteArray buf = reply->readAll(); 28 | 29 | //qDebug() << buf; 30 | QJsonParseError jsonError; 31 | QJsonDocument jsonRes = QJsonDocument::fromJson(buf, &jsonError);; 32 | 33 | 34 | if(jsonError.error == QJsonParseError::NoError) 35 | { 36 | if(jsonRes.isObject()) 37 | { 38 | QVariantMap result = jsonRes.toVariant().toMap(); 39 | QVariantMap dataList = result["data"].toMap(); 40 | 41 | foreach(QVariant data, dataList["songList"].toList()) 42 | { 43 | QVariantMap linkMap = data.toMap(); 44 | 45 | 46 | songInfo.songRealLink = linkMap["songLink"].toString(); 47 | songInfo.songName = linkMap["songName"].toString(); 48 | songInfo.artistName = linkMap["artistName"].toString(); 49 | songInfo.songPicSmall = linkMap["songPicSmall"].toString(); 50 | songInfo.songPicRadio = linkMap["songPicRadio"].toString(); 51 | songInfo.albumName = linkMap["albumName"].toString(); 52 | songInfo.lrcLink = linkMap["lrcLink"].toString(); 53 | } 54 | } 55 | } 56 | 57 | return songInfo; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /getsongreallink.h: -------------------------------------------------------------------------------- 1 | #ifndef GETSONGREALLINK_H 2 | #define GETSONGREALLINK_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | typedef struct _SONG_INFO 15 | { 16 | QString songRealLink; 17 | QString songName; 18 | QString artistName; 19 | QString songPicSmall; 20 | QString songPicRadio; 21 | QString time; 22 | QString albumName; 23 | QString lrcLink; 24 | QString size; 25 | }SONG_INFO; 26 | 27 | class GetSongRealLink : public QObject 28 | { 29 | Q_OBJECT 30 | public: 31 | explicit GetSongRealLink(QObject *parent = 0, QNetworkCookieJar *cookie = NULL); 32 | 33 | signals: 34 | 35 | public slots: 36 | 37 | SONG_INFO getSongRealLinkById(QString songId); 38 | 39 | private: 40 | QNetworkCookieJar *m_cookJar; 41 | }; 42 | 43 | #endif // GETSONGREALLINK_H 44 | -------------------------------------------------------------------------------- /img.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | img/play.svg 4 | img/pause.svg 5 | img/menu.svg 6 | img/lyricmask.png 7 | img/lrc.svg 8 | img/loop_random.svg 9 | img/loop_one.svg 10 | img/loop_no.svg 11 | img/loop_all.svg 12 | img/handle.png 13 | img/forward.svg 14 | img/cd.png 15 | img/backward.svg 16 | img/setting.png 17 | img/volume.png 18 | img/downLoad.png 19 | img/baidu.jpg 20 | img/cancel.png 21 | img/back.png 22 | img/play.png 23 | img/pause.png 24 | img/baiduFm.png 25 | 26 | 27 | -------------------------------------------------------------------------------- /img/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/back.png -------------------------------------------------------------------------------- /img/backward.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /img/baidu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/baidu.jpg -------------------------------------------------------------------------------- /img/baiduFm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/baiduFm.png -------------------------------------------------------------------------------- /img/cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/cancel.png -------------------------------------------------------------------------------- /img/cd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/cd.png -------------------------------------------------------------------------------- /img/downLoad.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/downLoad.png -------------------------------------------------------------------------------- /img/forward.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /img/handle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/handle.png -------------------------------------------------------------------------------- /img/loop_all.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 17 | 19 | 21 | 22 | 24 | 26 | 27 | -------------------------------------------------------------------------------- /img/loop_no.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 17 | 18 | 20 | 22 | 24 | 25 | -------------------------------------------------------------------------------- /img/loop_one.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 17 | 18 | 20 | 22 | 24 | 25 | 27 | 29 | 30 | -------------------------------------------------------------------------------- /img/loop_random.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 17 | 19 | 21 | 22 | 24 | 26 | 27 | -------------------------------------------------------------------------------- /img/lrc.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /img/lyricmask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/lyricmask.png -------------------------------------------------------------------------------- /img/menu.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 14 | 15 | 17 | 19 | 21 | 22 | 24 | 26 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /img/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/pause.png -------------------------------------------------------------------------------- /img/pause.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /img/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/play.png -------------------------------------------------------------------------------- /img/play.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /img/setting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/setting.png -------------------------------------------------------------------------------- /img/volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/img/volume.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | SHARE=/usr/share 4 | PIXMAP=/usr/share/pixmaps 5 | APP=/usr/share/applications 6 | BIN=/usr/bin 7 | 8 | if [ "$1" = "-u" ]; then 9 | rm $BIN/QBaiduFm 10 | rm $PIXMAP/baiduFm.png 11 | rm $APP/QBaiduFm.desktop 12 | rm -r $SHARE/QBaiduFm 13 | else 14 | mkdir -p $SHARE/QBaiduFm 15 | cp QBaiduFm $SHARE/QBaiduFm 16 | #mkdir -p $SHARE/QBaiduFm/lang/ 17 | #cp -r lang/*.qm $SHARE/QBaiduFm/lang/ 18 | rm -f $BIN/QBaiduFm 19 | ln -s $SHARE/QBaiduFm/QBaiduFm $BIN/QBaiduFm 20 | cp QBaiduFm.desktop $APP 21 | cp ./img/baiduFm.png $PIXMAP 22 | fi 23 | -------------------------------------------------------------------------------- /logindlg.cpp: -------------------------------------------------------------------------------- 1 | #include "logindlg.h" 2 | #include "ui_logindlg.h" 3 | #include 4 | #include 5 | 6 | //调用刚才的函数把获取的网页内容储存为一个qstring的变量 7 | const QString tokenUrl = "https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=true"; 8 | 9 | LoginDlg::LoginDlg(QWidget *parent, QNetworkCookieJar *cookie) : 10 | QFrame(parent), 11 | ui(new Ui::LoginDlg) 12 | { 13 | ui->setupUi(this); 14 | ui->verifywidget->hide(); 15 | 16 | m_iLoginError = USER_PASSWD_ERROR; 17 | 18 | if(!cookie) 19 | { 20 | qDebug() << "传入cookie失败!"; 21 | return; 22 | } 23 | m_cookJar = cookie; 24 | 25 | int iCheck = 0; 26 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm"); 27 | settings.beginGroup("User"); 28 | iCheck = settings.value("RememberMe").toInt(); 29 | m_userName = settings.value("UserName").toString(); 30 | m_passWd = settings.value("PassWd").toString(); 31 | 32 | // if(iCheck) 33 | // { 34 | // logIn(); 35 | // } 36 | settings.endGroup(); 37 | 38 | } 39 | 40 | LoginDlg::~LoginDlg() 41 | { 42 | delete ui; 43 | } 44 | 45 | int LoginDlg::logIn() 46 | { 47 | getWebResponse("http://www.baidu.com"); 48 | getWebResponse("https://passport.baidu.com/v2/api/?login"); 49 | QString url = "https://passport.baidu.com/v2/api/?login"; 50 | QByteArray ba; 51 | 52 | ba.append("ppui_logintime="); 53 | ba.append(QString::number(getRandNum(), 10)); 54 | ba.append("&charset=utf-8"); 55 | ba.append("&codestring="); 56 | ba.append("&token="); 57 | ba.append( getToken(tokenUrl)); 58 | ba.append("&isPhone=false"); 59 | ba.append("&index=0"); 60 | ba.append("&u="); 61 | ba.append("&safeflg=0"); 62 | ba.append("&staticpage=http%3A%2F%2Fwww.baidu.com%2Fcache%2Fuser%2Fhtml%2Fjump.html"); 63 | ba.append("&loginType=1"); 64 | ba.append("&tpl=mn"); 65 | ba.append("&callback=parent.bdPass.api.login._postCallback"); 66 | ba.append("&username="); 67 | ba.append(m_userName); 68 | ba.append("&password="); 69 | ba.append(m_passWd); 70 | ba.append("&verifycode="); 71 | ba.append("&mem_pass=on"); 72 | 73 | QString postRet = postWebResponse(url, ba); 74 | 75 | qDebug() << postRet; 76 | if(postRet.contains("error=0")) 77 | { 78 | qDebug() << "登录成功" << m_userName; 79 | m_iLoginError = LONIN_SUCCESS_ERROR; 80 | emit loginSuccess(m_userName); 81 | } 82 | else if(postRet.contains("error=2")) 83 | { 84 | qDebug() << "用户名密码错误"; 85 | m_iLoginError = USER_PASSWD_ERROR; 86 | emit loginSuccess("登录失败"); 87 | 88 | } 89 | else if(postRet.contains("error=5")) 90 | { 91 | qDebug() << "输入验证码"; 92 | m_iLoginError = VERIFY_PICTURE_ERROR; 93 | emit loginSuccess("登录失败"); 94 | } 95 | 96 | return m_iLoginError; 97 | } 98 | 99 | void LoginDlg::on_toolButtonLogIn_clicked() 100 | { 101 | if(m_iLoginError == LONIN_SUCCESS_ERROR) 102 | { 103 | emit loginSuccess(m_userName); 104 | hide(); 105 | return; 106 | } 107 | 108 | QString userName = ui->lineEditUserName->text(); 109 | QString passWd = ui->lineEditPasswd->text(); 110 | Qt::CheckState check = ui->checkBoxRememberMe->checkState(); 111 | 112 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm"); 113 | settings.beginGroup("User"); 114 | settings.setValue("RememberMe", check); 115 | if(check) 116 | { 117 | settings.setValue("UserName", userName); 118 | settings.setValue("PassWd", passWd); 119 | } 120 | settings.endGroup(); 121 | 122 | int iLoginSuccess = logIn(); 123 | if(iLoginSuccess == LONIN_SUCCESS_ERROR) 124 | { 125 | hide(); 126 | } 127 | else if(iLoginSuccess == USER_PASSWD_ERROR) 128 | { 129 | showDlg(USER_PASSWD_ERROR); 130 | } 131 | else if(iLoginSuccess == VERIFY_PICTURE_ERROR) 132 | { 133 | ui->verifywidget->show(); 134 | showDlg(VERIFY_PICTURE_ERROR); 135 | } 136 | } 137 | 138 | void LoginDlg::on_toolButtonCancel_clicked() 139 | { 140 | hide(); 141 | } 142 | 143 | void LoginDlg::showDlg(int iShowState) 144 | { 145 | if(iShowState == USER_PASSWD_ERROR) 146 | { 147 | ui->lineEditUserName->clear(); 148 | ui->lineEditPasswd->clear(); 149 | ui->lineEditUserName->setPlaceholderText("用户名或密码错误"); 150 | ui->lineEditPasswd->setPlaceholderText("用户名或密码错误"); 151 | } 152 | 153 | if(iShowState == VERIFY_PICTURE_ERROR) 154 | { 155 | ui->lineEditUserName->setPlaceholderText("请输入用户名"); 156 | ui->lineEditPasswd->setPlaceholderText("请输入密码"); 157 | } 158 | 159 | int iCheck = 0; 160 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm"); 161 | settings.beginGroup("User"); 162 | iCheck = settings.value("RememberMe").toInt(); 163 | ui->checkBoxRememberMe->setChecked(iCheck); 164 | m_userName = settings.value("UserName").toString(); 165 | m_passWd = settings.value("PassWd").toString(); 166 | 167 | if(iCheck) 168 | { 169 | ui->lineEditUserName->setText(m_userName); 170 | ui->lineEditPasswd->setText(m_passWd); 171 | } 172 | 173 | settings.endGroup(); 174 | show(); 175 | } 176 | 177 | int LoginDlg::getRandNum() 178 | { 179 | int irandNum = qrand() %(99999-10000+1)+10000; 180 | return irandNum; 181 | } 182 | 183 | QString LoginDlg::getWebResponse(QString url) 184 | { 185 | QNetworkAccessManager *manager = new QNetworkAccessManager; 186 | QNetworkRequest request; 187 | QByteArray responseData; 188 | 189 | manager->setCookieJar(m_cookJar); 190 | //设置网址 191 | request.setUrl(QUrl(url)); 192 | QNetworkReply *reply = manager->get(request); 193 | 194 | QEventLoop loop; 195 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 196 | loop.exec(); 197 | 198 | responseData = reply->readAll(); 199 | 200 | reply->deleteLater(); 201 | 202 | //qDebug() << responseData; 203 | return QString(responseData); //返回取到的源码字符串 204 | } 205 | 206 | QString LoginDlg::getToken(QString url) 207 | { 208 | QString response; 209 | response = getWebResponse(url); 210 | 211 | QRegExp rx; 212 | rx.setPattern("token='([0-9 | a-f]{1,})"); 213 | 214 | //下面就是匹配字符串(其实用正则更好) 215 | int start = rx.indexIn(response); 216 | int end = rx.matchedLength(); 217 | 218 | 219 | QString token = response.mid(start, end); 220 | 221 | token = token.mid(7, token.size()); 222 | 223 | // qDebug() << token; 224 | return token; //返回获取的token 225 | } 226 | 227 | 228 | QString LoginDlg::postWebResponse(QString url, QByteArray postData) 229 | { 230 | //qDebug() << postData; 231 | QNetworkAccessManager *manager = new QNetworkAccessManager; 232 | QNetworkRequest request; 233 | QByteArray responseData; 234 | 235 | manager->setCookieJar(m_cookJar); 236 | //设置网址 237 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); 238 | request.setHeader(QNetworkRequest::ContentLengthHeader, postData.length()); 239 | request.setUrl(QUrl(url)); 240 | QNetworkReply *reply = manager->post(request, postData); 241 | 242 | QEventLoop loop; 243 | connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); 244 | loop.exec(); 245 | 246 | responseData = reply->readAll(); 247 | 248 | 249 | // foreach(QNetworkCookie cookie, manager->cookieJar()->cookiesForUrl(QUrl(url))) 250 | // { 251 | // qDebug() << cookie.value(); 252 | // } 253 | 254 | reply->deleteLater(); 255 | 256 | // qDebug() << responseData; 257 | return QString(responseData); //返回取到的源码字符串 258 | } 259 | 260 | -------------------------------------------------------------------------------- /logindlg.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINDLG_H 2 | #define LOGINDLG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | 16 | enum LOGIN_ERROR 17 | { 18 | LONIN_SUCCESS_ERROR, 19 | USER_PASSWD_ERROR, 20 | VERIFY_PICTURE_ERROR 21 | }; 22 | 23 | namespace Ui { 24 | class LoginDlg; 25 | } 26 | 27 | class LoginDlg : public QFrame 28 | { 29 | Q_OBJECT 30 | 31 | public: 32 | explicit LoginDlg(QWidget *parent = 0, QNetworkCookieJar *cookie = NULL); 33 | ~LoginDlg(); 34 | 35 | private slots: 36 | void on_toolButtonLogIn_clicked(); 37 | 38 | void on_toolButtonCancel_clicked(); 39 | 40 | private: 41 | Ui::LoginDlg *ui; 42 | 43 | public: 44 | void showDlg(int iShowState = 0); 45 | int logIn(); 46 | 47 | private: 48 | int getRandNum(); 49 | QString getWebResponse(QString url); 50 | QString getToken(QString url); 51 | QString postWebResponse(QString url, QByteArray postData); 52 | 53 | private: 54 | QNetworkCookieJar *m_cookJar; 55 | 56 | int m_iLoginError; 57 | QString m_userName; 58 | QString m_passWd; 59 | 60 | signals: 61 | void loginSuccess(QString userName); 62 | }; 63 | 64 | #endif // LOGINDLG_H 65 | -------------------------------------------------------------------------------- /logindlg.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginDlg 4 | 5 | 6 | 7 | 0 8 | 0 9 | 242 10 | 222 11 | 12 | 13 | 14 | 登录框 15 | 16 | 17 | QFrame::StyledPanel 18 | 19 | 20 | QFrame::Raised 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 用户名 29 | 30 | 31 | 32 | 33 | 34 | 35 | Qt::Horizontal 36 | 37 | 38 | 39 | 20 40 | 24 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 0 50 | 0 51 | 52 | 53 | 54 | 55 | 140 56 | 27 57 | 58 | 59 | 60 | Qt::ImhSensitiveData 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 密码 72 | 73 | 74 | 75 | 76 | 77 | 78 | Qt::Horizontal 79 | 80 | 81 | 82 | 30 83 | 24 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 0 93 | 0 94 | 95 | 96 | 97 | 98 | 140 99 | 27 100 | 101 | 102 | 103 | Qt::ImhDialableCharactersOnly|Qt::ImhDigitsOnly|Qt::ImhEmailCharactersOnly|Qt::ImhExclusiveInputMask|Qt::ImhFormattedNumbersOnly|Qt::ImhHiddenText|Qt::ImhLatinOnly|Qt::ImhLowercaseOnly|Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhSensitiveData|Qt::ImhUppercaseOnly|Qt::ImhUrlCharactersOnly 104 | 105 | 106 | 107 | 108 | 109 | QLineEdit::Password 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | false 122 | 123 | 124 | 125 | 126 | 127 | 验证码 128 | 129 | 130 | 131 | 132 | 133 | 134 | Qt::Horizontal 135 | 136 | 137 | 138 | 5 139 | 20 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 0 149 | 0 150 | 151 | 152 | 153 | 154 | 90 155 | 27 156 | 157 | 158 | 159 | 7888 160 | 161 | 162 | 163 | 164 | 165 | 166 | Qt::Horizontal 167 | 168 | 169 | 170 | 6 171 | 20 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 3 8 5 2 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 记住本大人 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | Qt::Horizontal 199 | 200 | 201 | 202 | 40 203 | 20 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 登录 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | :/img/baidu.jpg:/img/baidu.jpg 222 | 223 | 224 | 225 | 40 226 | 40 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | Qt::Horizontal 235 | 236 | 237 | 238 | 24 239 | 38 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 我怕麻烦不登录 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | :/img/cancel.png:/img/cancel.png 258 | 259 | 260 | 261 | 40 262 | 40 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | Qt::Horizontal 271 | 272 | 273 | 274 | 40 275 | 20 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | checkBoxRememberMe 284 | 285 | 286 | verifywidget 287 | 288 | 289 | lineEditUserName 290 | lineEditPasswd 291 | 292 | 293 | 294 | 295 | 296 | 297 | -------------------------------------------------------------------------------- /lyrics.cpp: -------------------------------------------------------------------------------- 1 | #include "lyrics.h" 2 | #include "ui_lyrics.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | Lyrics::Lyrics(QWidget *parent) : 9 | QFrame(parent), 10 | ui(new Ui::Lyrics) 11 | { 12 | ui->setupUi(this); 13 | setFrameStyle(QFrame::NoFrame); 14 | ui->label->setWordWrap(true); 15 | ui->label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 16 | m_iCurrentIndex = 0; 17 | } 18 | 19 | Lyrics::~Lyrics() 20 | { 21 | delete ui; 22 | } 23 | 24 | void Lyrics::currentSongChannged(QString songName, QString aristName, QString ablumName) 25 | { 26 | m_songName = songName; 27 | m_aristName = aristName; 28 | m_ablumName = ablumName; 29 | 30 | QString lrc; 31 | lrc.clear(); 32 | lrc += QString("

"); 33 | lrc += m_aristName + "--" + m_songName; 34 | lrc += QString("

"); 35 | ui->label->setText(lrc); 36 | } 37 | 38 | void Lyrics::setLrc(QString lrc) 39 | { 40 | QTextStream stream(&lrc); 41 | QTextCodec *codec = QTextCodec::codecForName("utf-8"); 42 | stream.setCodec(codec); 43 | 44 | m_iCurrentIndex = 0; 45 | m_lyric.clear(); 46 | 47 | m_lyric = parse(stream); 48 | } 49 | 50 | QList Lyrics::parse(QTextStream &stream) 51 | { 52 | QRegExp timeExp; 53 | timeExp.setPatternSyntax(QRegExp::RegExp); 54 | timeExp.setCaseSensitivity(Qt::CaseSensitive); 55 | timeExp.setPattern("\\[([0-9]{2}):([0-9]{2})\\.([0-9]{2})\\]"); 56 | 57 | QList result; 58 | while (!stream.atEnd()) { 59 | QString line = stream.readLine(); 60 | int ret = timeExp.indexIn(line); 61 | QList ticks; 62 | int lastindex = 0; 63 | while (ret >= 0) { 64 | QStringList tstr = timeExp.capturedTexts(); 65 | QTime time(0, tstr[1].toInt(), tstr[2].toInt(), tstr[3].toInt()); 66 | ticks.append(time); 67 | lastindex = ret + timeExp.matchedLength(); 68 | ret = timeExp.indexIn(line, lastindex); 69 | } 70 | QString lyricstr = line.right(line.size() - lastindex); 71 | for (const QTime& t : ticks) { 72 | QLyric lyric; 73 | lyric.time = t.minute() * 60 * 1000 + t.second() * 1000 + t.msec(); 74 | 75 | lyric.lyric = lyricstr; 76 | 77 | // qDebug() << lyricstr; 78 | result.append(lyric); 79 | } 80 | } 81 | std::sort(result.begin(), result.end(), [] (const QLyric& a, const QLyric& b) -> bool { 82 | return a.time < b.time; 83 | }); 84 | 85 | return result; 86 | } 87 | 88 | 89 | void Lyrics::setTickLrc(qint64 position) 90 | { 91 | if(m_lyric.size() <= 0 || m_iCurrentIndex >= m_lyric.size()) 92 | return; 93 | 94 | 95 | for(int i = 0; i < m_lyric.size(); i++) 96 | { 97 | 98 | if(position > m_lyric.at(i).time) 99 | { 100 | m_iCurrentIndex = i; 101 | } 102 | } 103 | 104 | 105 | if(position > m_lyric.at(m_iCurrentIndex).time) 106 | { 107 | QString lrc; 108 | lrc.clear(); 109 | lrc += QString("

"); 110 | lrc += m_aristName + " - " + m_songName; 111 | lrc += QString("

"); 112 | 113 | for(int j = m_iCurrentIndex - 1; j < m_lyric.size(); j++) 114 | { 115 | if(j < 0) 116 | continue; 117 | 118 | if(m_iCurrentIndex == j) 119 | { 120 | lrc += QString("

"); 121 | lrc += m_lyric.at(m_iCurrentIndex).lyric; 122 | lrc += QString("

"); 123 | } 124 | else 125 | { 126 | lrc += "

"; 127 | lrc += m_lyric.at(j).lyric; 128 | lrc += "

"; 129 | } 130 | 131 | 132 | } 133 | ui->label->setText(lrc); 134 | m_iCurrentIndex++; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /lyrics.h: -------------------------------------------------------------------------------- 1 | #ifndef LYRICS_H 2 | #define LYRICS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class Lyrics; 11 | } 12 | 13 | struct QLyric 14 | { 15 | qint64 time; 16 | QString lyric; 17 | }; 18 | 19 | class Lyrics : public QFrame 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit Lyrics(QWidget *parent = 0); 25 | ~Lyrics(); 26 | 27 | private: 28 | Ui::Lyrics *ui; 29 | QList parse(QTextStream &stream); 30 | QList m_lyric; 31 | 32 | QString m_songName; 33 | QString m_aristName; 34 | QString m_ablumName; 35 | 36 | 37 | int m_iCurrentIndex; 38 | public: 39 | void setLrc(QString lrc); 40 | 41 | void currentSongChannged(QString songName, QString aristName, QString ablumName); 42 | public slots: 43 | void setTickLrc(qint64 position); 44 | }; 45 | 46 | #endif // LYRICS_H 47 | -------------------------------------------------------------------------------- /lyrics.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Lyrics 4 | 5 | 6 | 7 | 0 8 | 0 9 | 758 10 | 554 11 | 12 | 13 | 14 | Frame 15 | 16 | 17 | QFrame::StyledPanel 18 | 19 | 20 | QFrame::Raised 21 | 22 | 23 | 24 | 25 | 26 | <html><head/><body><p align="center"><span style=" font-weight:600;">平凡之路</span></p><p align="center">作词:韩寒,朴树</p><p align="center">作曲:朴树</p><p align="center"><span style=" font-weight:600; color:#aaaa00;">演唱:朴树</span></p><p align="center">徘徊着的 在路上的</p><p align="center">你要走吗</p><p align="center">易碎的 骄傲着</p><p align="center">那也曾是我的模样</p><p align="center">沸腾着的 不安着的</p><p align="center">你要去哪</p><p align="center">谜一样的 沉默着的</p><p align="center">故事你真的在听吗</p><p align="center">我曾经跨过山和大海 也穿过人山人海 我曾经拥有着一切 转眼都飘散如烟 我曾经失落失望失掉所有方向 直到看见平凡才是唯一的答案</p><p align="justify">当你仍然 还在幻想</p><p align="justify">你的明天</p><p align="center">她会好吗 还是更烂</p><p align="center">对我而言是另一天</p><p align="center">我曾经毁了我的一切 只想永远地离开 我曾经堕入无边黑暗 想挣扎无法自拔 我曾经象你象他象那野草野花 绝望着 渴望着 哭着笑着平凡着</p><p align="center">向前走 就这么走 就算你被给过什么 向前走 就这么走 就算你被夺走什么 向前走 就这么走 就算你会错过什么 向前走 就这么走 就算你会</p><p align="center">我曾经跨过山和大海 也穿过人山人海 我曾经拥有着一切 转眼都飘散如烟 我曾经失落失望失掉所有方向 直到看见平凡才是唯一的答案</p><p align="center">我曾经毁了我的一切 只想永远地离开 我曾经堕入无边黑暗 想挣扎无法自拔 我曾经像你像他像那野草野花 绝望着 渴望着 哭着笑着平凡着</p></body></html> 27 | 28 | 29 | Qt::AlignCenter 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | Widget w; 10 | 11 | QHotkey hotkey(QKeySequence("ctrl+alt+Q"), true);//The hotkey will be automatically registered 12 | qDebug() << "Is Registered: " << hotkey.isRegistered(); 13 | 14 | QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){ 15 | qDebug() << "Hotkey Activated - the application will quit now"; 16 | qApp->quit(); 17 | }); 18 | 19 | 20 | QHotkey hotkeyPrev(QKeySequence("ctrl+left"), true);//The hotkey will be automatically registered 21 | QObject::connect(&hotkeyPrev, &QHotkey::activated, &w, &Widget::on_prevtoolButton_clicked); 22 | 23 | 24 | QHotkey hotkeyNext(QKeySequence("ctrl+right"), true);//The hotkey will be automatically registered 25 | QObject::connect(&hotkeyNext, &QHotkey::activated, &w, &Widget::on_nexttoolButton_clicked); 26 | 27 | 28 | 29 | QDesktopWidget *pDesk = QApplication::desktop(); 30 | w.move((pDesk->width() - w.width()) / 2, (pDesk->height() - w.height()) / 8); 31 | 32 | w.setWindowIcon(QIcon(":/img/baiduFm.png")); 33 | w.show(); 34 | 35 | return a.exec(); 36 | } 37 | -------------------------------------------------------------------------------- /qhotkey.pri: -------------------------------------------------------------------------------- 1 | CONFIG += C++11 2 | 3 | HEADERS += $$PWD/QHotkey/qhotkey.h \ 4 | $$PWD/QHotkey/qhotkey_p.h 5 | 6 | SOURCES += $$PWD/QHotkey/qhotkey.cpp 7 | 8 | mac { 9 | SOURCES += $$PWD/QHotkey/qhotkey_mac.cpp 10 | LIBS += -framework Carbon 11 | } else:win32 { 12 | SOURCES += $$PWD/QHotkey/qhotkey_win.cpp 13 | LIBS += -luser32 14 | } else:unix { 15 | SOURCES += $$PWD/QHotkey/qhotkey_x11.cpp 16 | QT += x11extras 17 | LIBS += -lX11 18 | } 19 | 20 | INCLUDEPATH += $$PWD/QHotkey 21 | -------------------------------------------------------------------------------- /screenshot/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/screenshot/download.png -------------------------------------------------------------------------------- /screenshot/ubuntu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/screenshot/ubuntu.png -------------------------------------------------------------------------------- /screenshot/win10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spygg/QBaiduFm/6a40aeff291a60911fd8a149a28febf42d4a8803/screenshot/win10.png -------------------------------------------------------------------------------- /volpannel.cpp: -------------------------------------------------------------------------------- 1 | #include "volpannel.h" 2 | #include 3 | 4 | volPannel::volPannel(QWidget *parent):QSlider(parent) 5 | { 6 | 7 | } 8 | 9 | 10 | void volPannel::leaveEvent(QEvent *) 11 | { 12 | setVisible(false); 13 | } 14 | -------------------------------------------------------------------------------- /volpannel.h: -------------------------------------------------------------------------------- 1 | #ifndef VOLPANNEL_H 2 | #define VOLPANNEL_H 3 | #include 4 | 5 | class volPannel : public QSlider 6 | { 7 | Q_OBJECT 8 | public: 9 | volPannel(QWidget *parent = 0); 10 | 11 | private: 12 | 13 | void leaveEvent(QEvent *); 14 | }; 15 | 16 | #endif // VOLPANNEL_H 17 | -------------------------------------------------------------------------------- /widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "ui_widget.h" 3 | #include "lyrics.h" 4 | #include "aristpicture.h" 5 | #include "downloadfile.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | Widget::Widget(QWidget *parent) : 13 | QWidget(parent), 14 | ui(new Ui::Widget) 15 | { 16 | ui->setupUi(this); 17 | layout()->setSizeConstraint(QLayout::SetFixedSize); 18 | layout()->setAlignment( Qt::AlignHCenter); 19 | m_cookJar = new QNetworkCookieJar; 20 | m_userLonIndlg = new LoginDlg(0, m_cookJar); 21 | m_channelWidget = new ChannelsWidget(0, m_cookJar); 22 | m_pPlayer = new QMediaPlayer(this); 23 | m_iCurrentSongIndex = 0; 24 | ui->volSlider->hide(); 25 | ui->channelwidget->hide(); 26 | 27 | 28 | 29 | connect(m_userLonIndlg, SIGNAL(loginSuccess(QString)), ui->aristPicWidget, SLOT(userLoninSlot(QString))); 30 | connect(this, SIGNAL(channelInfoSignal(QString)), ui->aristPicWidget, SLOT(channelChangedSlot(QString))); 31 | connect(ui->channelwidget, SIGNAL(channelChanged(CHANNEL_INFO)), this, SLOT(channelChangedSlot(CHANNEL_INFO))); 32 | connect(m_pPlayer, &QMediaPlayer::mediaStatusChanged, this, &Widget::mediaStatusChanged); 33 | connect(m_pPlayer, &QMediaPlayer::positionChanged, this, &Widget::positionChanged); 34 | connect(m_pPlayer, &QMediaPlayer::durationChanged, this, &Widget::durationChanged); 35 | connect(m_pPlayer, SIGNAL(positionChanged(qint64)), ui->lycWidget, SLOT(setTickLrc(qint64))); 36 | connect(m_pPlayer, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(errorOccur(QMediaPlayer::Error))); 37 | connect(ui->volSlider, &QSlider::valueChanged, this, &Widget::volChannged); 38 | connect(ui->progressSlider, &QSlider::sliderMoved, this, &Widget::setPosition); 39 | connect(ui->aristPicWidget, SIGNAL(pauseSignal(bool)), this, SLOT(pauseSlot(bool))); 40 | connect(m_pPlayer, SIGNAL(durationChanged(qint64)), ui->aristPicWidget, SLOT(setDefultPic(qint64))); 41 | connect(m_pPlayer, SIGNAL(positionChanged(qint64)), ui->aristPicWidget, SLOT(positionChanged(qint64))); 42 | 43 | ui->volSlider->setRange(0, 100); 44 | ui->volSlider->setValue(60); 45 | 46 | //歌曲频道信息 47 | QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QBaiduFm", "QBaiduFm"); 48 | settings.beginGroup("User"); 49 | int iChannel = settings.value("ChannelIndex").toInt(); 50 | int iCheck = settings.value("RememberMe").toInt(); 51 | settings.endGroup(); 52 | 53 | //登录 54 | if(iCheck) 55 | { 56 | m_userLonIndlg->logIn(); 57 | } 58 | //获取频道列表 59 | ui->channelwidget->channelSelected(iChannel); 60 | } 61 | 62 | void Widget::errorOccur(QMediaPlayer::Error error) 63 | { 64 | ui->lycWidget->setLrc(m_pPlayer->errorString()); 65 | 66 | qDebug() << "User Debug ---->error occured!" << m_pPlayer->errorString() << error; 67 | 68 | if(QMediaPlayer::NetworkError != error) 69 | { 70 | nextSong(); 71 | } 72 | } 73 | 74 | void Widget::pauseSlot(bool pause) 75 | { 76 | if(pause) 77 | m_pPlayer->pause(); 78 | else 79 | m_pPlayer->play(); 80 | } 81 | 82 | void Widget::volChannged(qint64 position) 83 | { 84 | m_pPlayer->setVolume(position); 85 | } 86 | 87 | void Widget::mediaStatusChanged(QMediaPlayer::MediaStatus status) 88 | { 89 | if(status == QMediaPlayer::EndOfMedia || 90 | status == QMediaPlayer::NoMedia || 91 | status == QMediaPlayer::InvalidMedia) 92 | { 93 | //qDebug() << "播放完成"; 94 | nextSong(); 95 | } 96 | } 97 | 98 | void Widget::durationChanged(qint64 duration) 99 | { 100 | ui->progressSlider->setRange(0, duration); 101 | } 102 | 103 | void Widget::setPosition(qint64 position) 104 | { 105 | m_pPlayer->setPosition(position); 106 | } 107 | 108 | void Widget::positionChanged(qint64 position) 109 | { 110 | ui->progressSlider->setValue(position); 111 | } 112 | 113 | 114 | void Widget::channelChangedSlot(CHANNEL_INFO channel) 115 | { 116 | m_songIdList.clear(); 117 | m_iCurrentSongIndex = 0; 118 | 119 | 120 | m_currentChannelId.channelId = channel.channelId; 121 | m_currentChannelId.channelName = channel.channelName; 122 | 123 | //初始化某个频道列表下的所有歌曲 124 | initSongIdList(); 125 | } 126 | 127 | void Widget::initSongIdList() 128 | { 129 | //第二步,获取某个频道下的歌曲ID列表 130 | GetSongPlayListId getPlayListId(this, m_cookJar); 131 | m_songIdList = getPlayListId.getSongIdList(m_currentChannelId.channelId); 132 | 133 | qDebug() << "频道:" << m_currentChannelId.channelName << m_currentChannelId.channelId<< "共有歌曲" << m_songIdList.size(); 134 | 135 | 136 | QString info = m_currentChannelId.channelName + " 共有歌曲: " + QString::number(m_songIdList.size()); 137 | emit channelInfoSignal(info); 138 | m_iCurrentSongIndex = 0; 139 | play(0); 140 | } 141 | 142 | Widget::~Widget() 143 | { 144 | delete m_userLonIndlg; 145 | delete ui; 146 | } 147 | 148 | void Widget::on_settingtoolButton_clicked() 149 | { 150 | m_userLonIndlg->showDlg(); 151 | } 152 | 153 | void Widget::closeEvent(QCloseEvent *) 154 | { 155 | m_userLonIndlg->close(); 156 | } 157 | 158 | void Widget::on_voltoolButton_clicked() 159 | { 160 | if(ui->volSlider->isHidden()) 161 | { 162 | ui->volSlider->show(); 163 | } 164 | else 165 | ui->volSlider->hide(); 166 | } 167 | 168 | void Widget::on_prevtoolButton_clicked() 169 | { 170 | prevSong(); 171 | } 172 | 173 | void Widget::on_nexttoolButton_clicked() 174 | { 175 | nextSong(); 176 | } 177 | 178 | void Widget::on_showChanneltoolButton_clicked() 179 | { 180 | if(ui->channelwidget->isHidden()) 181 | { 182 | ui->channelwidget->show(); 183 | 184 | // QPropertyAnimation *anim = new QPropertyAnimation(ui->channelwidget, "geometry"); 185 | // anim->setDuration(1500); 186 | 187 | // anim->setEasingCurve(QEasingCurve::OutCubic); 188 | // ui->channelwidget->setVisible(true); 189 | // connect(anim, &QPropertyAnimation::finished, [this] () { 190 | // ui->channelwidget->setVisible(false); 191 | // }); 192 | // anim->start(QPropertyAnimation::DeleteWhenStopped); 193 | 194 | } 195 | else 196 | ui->channelwidget->hide(); 197 | } 198 | 199 | 200 | void Widget::prevSong() 201 | { 202 | qDebug() << "上一曲"; 203 | 204 | if(m_iCurrentSongIndex <= 0) 205 | { 206 | initSongIdList(); 207 | return; 208 | } 209 | 210 | m_iCurrentSongIndex--; 211 | 212 | play(m_iCurrentSongIndex); 213 | } 214 | 215 | 216 | void Widget::nextSong() 217 | { 218 | qDebug() << "下一首" << m_iCurrentSongIndex << m_songIdList.size(); 219 | if(m_iCurrentSongIndex >= m_songIdList.size()) 220 | { 221 | initSongIdList(); 222 | return; 223 | } 224 | 225 | m_iCurrentSongIndex++; 226 | 227 | play(m_iCurrentSongIndex); 228 | } 229 | 230 | void Widget::play(int index) 231 | { 232 | if(index >= m_songIdList.size() || index < 0) 233 | return; 234 | 235 | GetSongRealLink getSongLink; 236 | m_currentSongInfo = getSongLink.getSongRealLinkById(m_songIdList.at(index)); 237 | 238 | m_pPlayer->setMedia(QUrl(m_currentSongInfo.songRealLink)); 239 | m_pPlayer->play(); 240 | 241 | 242 | //获取歌词 243 | GetLrc getLrc; 244 | QString lrc = getLrc.getLrc(m_currentSongInfo.lrcLink); 245 | ui->lycWidget->currentSongChannged(m_currentSongInfo.songName, m_currentSongInfo.artistName, m_currentSongInfo.albumName); 246 | ui->lycWidget->setLrc(lrc); 247 | 248 | //显示歌手图片 249 | GetAristPic getPic; 250 | QPixmap picMap = getPic.getAristPic(m_currentSongInfo.songPicRadio); 251 | ui->aristPicWidget->setAristPic(picMap); 252 | } 253 | 254 | 255 | //下载歌曲 256 | void Widget::on_downloadtoolButton_clicked() 257 | { 258 | QString fileName; 259 | DownLoadFile downMp3; 260 | 261 | QDir dir; 262 | if(!dir.exists("./download")) 263 | { 264 | dir.mkdir("./download"); 265 | } 266 | fileName = "./download/" + m_currentSongInfo.songName + ".mp3"; 267 | 268 | qDebug() << fileName; 269 | 270 | downMp3.getMp3File(fileName, m_currentSongInfo.songRealLink); 271 | 272 | qDebug() << "下载完成"; 273 | } 274 | -------------------------------------------------------------------------------- /widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "logindlg.h" 16 | #include "channelswidget.h" 17 | #include "lyrics.h" 18 | #include "volpannel.h" 19 | #include "widget.h" 20 | #include "aristpicture.h" 21 | #include "getsongplaylistid.h" 22 | #include "getsongreallink.h" 23 | #include "getaristpic.h" 24 | #include "getlrc.h" 25 | 26 | namespace Ui { 27 | class Widget; 28 | } 29 | 30 | class Widget : public QWidget 31 | { 32 | Q_OBJECT 33 | 34 | public: 35 | explicit Widget(QWidget *parent = 0); 36 | ~Widget(); 37 | 38 | public slots: 39 | void on_settingtoolButton_clicked(); 40 | 41 | void on_voltoolButton_clicked(); 42 | 43 | void on_showChanneltoolButton_clicked(); 44 | 45 | void channelChangedSlot(CHANNEL_INFO channel); 46 | void on_nexttoolButton_clicked(); 47 | 48 | void on_prevtoolButton_clicked(); 49 | 50 | void pauseSlot(bool pause); 51 | void on_downloadtoolButton_clicked(); 52 | 53 | private: 54 | Ui::Widget *ui; 55 | void closeEvent(QCloseEvent *event); 56 | 57 | 58 | private: 59 | QMediaPlayer *m_pPlayer; 60 | LoginDlg *m_userLonIndlg; 61 | CHANNEL_INFO m_currentChannelId; 62 | ChannelsWidget *m_channelWidget; 63 | QList m_songIdList; 64 | int m_iCurrentSongIndex; 65 | SONG_INFO m_currentSongInfo; 66 | 67 | QNetworkCookieJar *m_cookJar; 68 | void play(int index); 69 | void nextSong(); 70 | void prevSong(); 71 | void initSongIdList(); 72 | void mediaStatusChanged(QMediaPlayer::MediaStatus status); 73 | void positionChanged(qint64 position); 74 | void durationChanged(qint64 duration); 75 | void setPosition(qint64 position); 76 | void volChannged(qint64 position); 77 | 78 | signals: 79 | void channelInfoSignal(QString channel); 80 | private slots: 81 | void errorOccur(QMediaPlayer::Error); 82 | }; 83 | 84 | #endif // WIDGET_H 85 | 86 | 87 | -------------------------------------------------------------------------------- /widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 315 10 | 583 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | Qt::NoContextMenu 21 | 22 | 23 | QBaiduFm 24 | 25 | 26 | 1.000000000000000 27 | 28 | 29 | 30 | 9 31 | 32 | 33 | 9 34 | 35 | 36 | 9 37 | 38 | 39 | 9 40 | 41 | 42 | 9 43 | 44 | 45 | 46 | 47 | 0 48 | 49 | 50 | 51 | 52 | 53 | 200 54 | 220 55 | 56 | 57 | 58 | 59 | 200 60 | 220 61 | 62 | 63 | 64 | true 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 0 73 | 0 74 | 75 | 76 | 77 | 78 | 200 79 | 240 80 | 81 | 82 | 83 | 84 | 200 85 | 240 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 240 95 | 21 96 | 97 | 98 | 99 | Qt::Horizontal 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 9 108 | 109 | 110 | 9 111 | 112 | 113 | 9 114 | 115 | 116 | 9 117 | 118 | 119 | 9 120 | 121 | 122 | 123 | 124 | 125 | 16777215 126 | 40 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | :/img/backward.svg 135 | 136 | 137 | 138 | 139 | 40 140 | 40 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 16777215 150 | 40 151 | 152 | 153 | 154 | Next 155 | 156 | 157 | 158 | 159 | 160 | 161 | :/img/forward.svg 162 | 163 | 164 | 165 | 166 | 40 167 | 40 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 16777215 177 | 40 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | :/img/downLoad.png:/img/downLoad.png 186 | 187 | 188 | 189 | 40 190 | 40 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 0 205 | 206 | 207 | 0 208 | 209 | 210 | 0 211 | 212 | 213 | 0 214 | 215 | 216 | 0 217 | 218 | 219 | 220 | 221 | Qt::Vertical 222 | 223 | 224 | 225 | 20 226 | 40 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 登录百度 235 | 236 | 237 | 0 238 | 239 | 240 | Login 241 | 242 | 243 | 244 | 245 | 246 | 247 | :/img/setting.png:/img/setting.png 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | :/img/lrc.svg 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | :/img/volume.png:/img/volume.png 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 29 279 | 90 280 | 281 | 282 | 283 | Qt::Vertical 284 | 285 | 286 | 287 | 288 | 289 | 290 | Qt::Vertical 291 | 292 | 293 | 294 | 20 295 | 40 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 0 308 | 0 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | AristPicture 319 | QWidget 320 |
aristpicture.h
321 | 1 322 |
323 | 324 | Lyrics 325 | QWidget 326 |
lyrics.h
327 | 1 328 |
329 | 330 | volPannel 331 | QSlider 332 |
volpannel.h
333 |
334 | 335 | ChannelsWidget 336 | QWidget 337 |
channelswidget.h
338 | 1 339 |
340 |
341 | 342 | 343 | 344 | 345 |
346 | --------------------------------------------------------------------------------