├── LICENSE ├── doc └── notes.rst ├── readme.rst └── src ├── core ├── insertoperation.cpp ├── insertoperation.h ├── operationitem.cpp ├── operationitem.h ├── operationmodel.cpp ├── operationmodel.h ├── renameritem.cpp ├── renameritem.h ├── renamermodel.cpp └── renamermodel.h ├── image └── icon │ └── metamorphose.ico ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── metamorphose3.pro ├── operation ├── insertform.cpp ├── insertform.h └── insertform.ui ├── operationformitem.cpp ├── operationformitem.h ├── operationformitem.ui ├── operationformmodel.cpp ├── operationformmodel.h ├── operationsform.cpp ├── operationsform.h ├── operationsform.ui ├── resources.qrc ├── selectionform.cpp ├── selectionform.h ├── selectionform.ui ├── selectwidget.cpp ├── suboperationsform.cpp ├── suboperationsform.h └── suboperationsform.ui /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 | -------------------------------------------------------------------------------- /doc/notes.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Notes 3 | ===== 4 | 5 | Workflow 6 | ======== 7 | 8 | #. Select items: 9 | 10 | - filter options 11 | 12 | #. Sort: 13 | 14 | - sorting options 15 | - manual sort 16 | 17 | #. Add operations (works on basename and path?): 18 | 19 | - insert 20 | - replace 21 | - move text 22 | - modify text 23 | - adjust length 24 | 25 | #. Preview: 26 | 27 | - show warnings 28 | 29 | #. Rename: 30 | 31 | - handle FS errors 32 | 33 | Sub-operations (tags) 34 | ===================== 35 | 36 | - text in between ":" 37 | - applies operation to current name 38 | - completely configurable via GUI 39 | - possible actions: 40 | 41 | - counter 42 | - file metadata 43 | - image Exif data 44 | -------------------------------------------------------------------------------- /readme.rst: -------------------------------------------------------------------------------- 1 | ************** 2 | Métamorphose 3 3 | ************** 4 | 5 | Proof of concept 6 | ================ 7 | 8 | **DO NOT CLONE** 9 | 10 | **DO NOT BUILD** 11 | 12 | **DO NOT USE** 13 | 14 | ... and go away!! -------------------------------------------------------------------------------- /src/core/insertoperation.cpp: -------------------------------------------------------------------------------- 1 | #include "insertoperation.h" 2 | 3 | /** 4 | * Performed for every item in the renamer list. 5 | */ 6 | void InsertOperation::operation(QString &name) 7 | { 8 | QString parsedText = parseSubOps(); 9 | 10 | switch (positionType) { 11 | case Prefix: 12 | name.prepend(parsedText); 13 | break; 14 | case Suffix: 15 | name.append(parsedText); 16 | break; 17 | case Fixed: 18 | if (atPosition < name.length()) { 19 | name.insert(atPosition, parsedText); 20 | } 21 | else { 22 | name.append(parsedText); 23 | } 24 | break; 25 | case BeforeText: 26 | name.replace(textToSearch, parsedText + textToSearch, caseSensitivity); 27 | break; 28 | case AfterText: 29 | name.replace(textToSearch, textToSearch + parsedText, caseSensitivity); 30 | break; 31 | default: 32 | qCWarning(M3CORE) << "unhandled PositionType"; 33 | break; 34 | } 35 | } 36 | 37 | void InsertOperation::setPositionType(const PositionTypes type) 38 | { 39 | positionType = type; 40 | } 41 | 42 | void InsertOperation::setPosition(const int position) 43 | { 44 | atPosition = position; 45 | } 46 | 47 | void InsertOperation::setTextToInsert(const QString text) 48 | { 49 | textToInsert = text; 50 | } 51 | 52 | void InsertOperation::setTextToSearch(const QString text) 53 | { 54 | textToSearch = text; 55 | } 56 | 57 | void InsertOperation::setCaseSensitive(const bool isCaseSensitive) 58 | { 59 | if (!isCaseSensitive) { 60 | caseSensitivity = Qt::CaseInsensitive; 61 | } 62 | else { 63 | caseSensitivity = Qt::CaseSensitive; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/core/insertoperation.h: -------------------------------------------------------------------------------- 1 | #ifndef INSERTOPERATION_H 2 | #define INSERTOPERATION_H 3 | 4 | #include 5 | #include "operationitem.h" 6 | 7 | class InsertOperation : public OperationItem 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | enum PositionType { 13 | Prefix = 0, 14 | Suffix = 1, 15 | Fixed = 2, 16 | BeforeText = 3, 17 | AfterText = 4 18 | }; 19 | Q_DECLARE_FLAGS(PositionTypes, PositionType) 20 | void setPositionType(const InsertOperation::PositionTypes type); 21 | void setPosition(const int position); 22 | void setTextToInsert(const QString text); 23 | void setTextToSearch(const QString text); 24 | void setCaseSensitive(const bool isCaseSensitive); 25 | 26 | protected: 27 | void operation(QString &name) override; 28 | 29 | private: 30 | PositionTypes positionType; 31 | int atPosition; 32 | QString textToSearch; 33 | Qt::CaseSensitivity caseSensitivity; 34 | }; 35 | 36 | #endif // INSERTOPERATION_H 37 | -------------------------------------------------------------------------------- /src/core/operationitem.cpp: -------------------------------------------------------------------------------- 1 | #include "operationitem.h" 2 | 3 | /** 4 | * Apply the operation to the given item's name. 5 | * Called by OperationModel::applyOperations 6 | */ 7 | void OperationItem::applyOperation(int itemPosition, std::pair &name) 8 | { 9 | this->itemPosition = itemPosition; 10 | 11 | if (applyToName) { 12 | operation(name.first); 13 | } 14 | if (applyToExtension) { 15 | operation(name.second); 16 | } 17 | } 18 | 19 | /** 20 | * Innermost loop! 21 | */ 22 | QString OperationItem::parseSubOps() 23 | { 24 | QStringList segments = parsedTextSegments; 25 | 26 | qCDebug(M3CORE) << "parsing subops segments" << segments; 27 | 28 | for (int i = 0; i < segments.size(); ++i) { 29 | QString segment = segments.at(i); 30 | 31 | if (segment == "numb") { 32 | segments[i] = numbering(); 33 | } 34 | if (segment == "date") { 35 | segments[i] = datetime("yyyy-MM-dd"); 36 | } 37 | if (segment == "time") { 38 | segments[i] = datetime("hh-mm-ss"); 39 | } 40 | } 41 | return segments.join(""); 42 | } 43 | 44 | void OperationItem::setApplyToName(const bool apply) 45 | { 46 | applyToName = apply; 47 | } 48 | 49 | void OperationItem::setApplyToExtension(const bool apply) 50 | { 51 | applyToExtension = apply; 52 | } 53 | 54 | /** 55 | * Run once before running applyOperation on each item. 56 | * Called by RenamerModel::applyRenamingOps. 57 | */ 58 | void OperationItem::preprocess() 59 | { 60 | qCDebug(M3CORE) << "pre-process subops in" << textToInsert; 61 | 62 | parsedTextSegments = textToInsert.split(":", QString::SkipEmptyParts); 63 | 64 | // TODO: 65 | // depending on date & time type, pre-calculate 66 | // if numbering, calculate final count? 67 | } 68 | 69 | QString OperationItem::numbering() 70 | { 71 | int numb = itemPosition + 1; 72 | return QString("%1").arg(numb, 3, 10, QChar('0')); 73 | } 74 | 75 | QString OperationItem::datetime(const QString format) 76 | { 77 | QDateTime datetime = QDateTime::currentDateTime(); 78 | return datetime.toString(format); 79 | } 80 | -------------------------------------------------------------------------------- /src/core/operationitem.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONITEM_H 2 | #define OPERATIONITEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | Q_DECLARE_LOGGING_CATEGORY(M3CORE) 9 | 10 | class OperationItem : public QObject 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | void applyOperation(int itemPosition, std::pair &name); 16 | void setApplyToName(const bool apply); 17 | void setApplyToExtension(const bool apply); 18 | QString parseSubOps(); 19 | void preprocess(); 20 | QString numbering(); 21 | QString datetime(const QString format); 22 | 23 | protected: 24 | virtual void operation(QString &name) = 0; 25 | int itemPosition; 26 | QString textToInsert; 27 | QStringList parsedTextSegments; 28 | 29 | private: 30 | bool applyToName = true; 31 | bool applyToExtension = false; 32 | }; 33 | 34 | #endif // OPERATIONITEM_H 35 | -------------------------------------------------------------------------------- /src/core/operationmodel.cpp: -------------------------------------------------------------------------------- 1 | #include "operationmodel.h" 2 | 3 | OperationModel::OperationModel(QObject *parent) 4 | : QAbstractTableModel(parent) 5 | { 6 | 7 | } 8 | 9 | OperationModel::~OperationModel() 10 | { 11 | qDeleteAll(itemsList); 12 | } 13 | 14 | /** 15 | * Removes all items from the model. 16 | */ 17 | void OperationModel::clear() 18 | { 19 | if (!itemsList.isEmpty()) { 20 | beginResetModel(); 21 | qCDebug(M3CORE) << "Clearing operations..."; 22 | itemsList.clear(); 23 | endResetModel(); 24 | } 25 | } 26 | 27 | bool OperationModel::isEmpty() const 28 | { 29 | return itemsList.isEmpty(); 30 | } 31 | 32 | int OperationModel::columnCount(const QModelIndex &parent) const 33 | { 34 | return 2; 35 | } 36 | 37 | int OperationModel::rowCount(const QModelIndex &parent) const 38 | { 39 | return itemsList.size(); 40 | } 41 | 42 | QVariant OperationModel::headerData(int section, Qt::Orientation orientation, int role) const 43 | { 44 | if (role != Qt::DisplayRole) { 45 | return QVariant(); 46 | } 47 | if (orientation == Qt::Horizontal) { 48 | QString header; 49 | switch (section) { 50 | case 0: 51 | header = QString(" "); 52 | break; 53 | case 1: 54 | header = tr("Type"); 55 | break; 56 | default: 57 | break; 58 | } 59 | return header; 60 | } 61 | else if (orientation == Qt::Vertical) { 62 | return section + 1; 63 | } 64 | return QVariant(); 65 | } 66 | 67 | QVariant OperationModel::data(const QModelIndex &index, int role) const 68 | { 69 | if (!index.isValid()) { 70 | return QVariant(); 71 | } 72 | QVariant data; 73 | if (role == Qt::ToolTipRole) { 74 | data = "tooltip data"; 75 | } 76 | else if (role == Qt::DisplayRole || role == Qt::EditRole) { 77 | switch (index.column()) { 78 | case 0: 79 | data = true; 80 | break; 81 | case 1: 82 | data = "Insert"; 83 | break; 84 | default: 85 | break; 86 | } 87 | } 88 | return data; 89 | } 90 | 91 | void OperationModel::addOperation(OperationItem *operation) 92 | { 93 | int size = itemsList.size(); 94 | beginInsertRows(parentItem, size, size); 95 | itemsList.append(operation); 96 | endInsertRows(); 97 | } 98 | 99 | void OperationModel::preProcessOperations() 100 | { 101 | for (OperationItem *op : itemsList) { 102 | op->preprocess(); 103 | } 104 | } 105 | 106 | std::pair OperationModel::applyOperations(const int &index, 107 | std::pair oldName) 108 | { 109 | std::pair newName = std::make_pair(QString("%1").arg(oldName.first), 110 | QString("%1").arg(oldName.second)); 111 | for (OperationItem *op : itemsList) { 112 | op->applyOperation(index, newName); 113 | } 114 | return newName; 115 | } 116 | -------------------------------------------------------------------------------- /src/core/operationmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONMODEL_H 2 | #define OPERATIONMODEL_H 3 | 4 | #include 5 | #include "operationitem.h" 6 | 7 | class OperationModel : public QAbstractTableModel 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | explicit OperationModel(QObject *parent = 0); 13 | ~OperationModel(); 14 | 15 | QVariant data(const QModelIndex &index, 16 | int role = Qt::DisplayRole) const override; 17 | QVariant headerData(int section, 18 | Qt::Orientation orientation, 19 | int role = Qt::DisplayRole) const override; 20 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 21 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 22 | void addOperation(OperationItem *operation); 23 | void preProcessOperations(); 24 | std::pair applyOperations(const int &index, std::pair oldName); 25 | void clear(); 26 | bool isEmpty() const; 27 | 28 | protected: 29 | QModelIndex parentItem; 30 | 31 | private: 32 | QList itemsList; 33 | }; 34 | 35 | #endif // OPERATIONMODEL_H 36 | -------------------------------------------------------------------------------- /src/core/renameritem.cpp: -------------------------------------------------------------------------------- 1 | #include "renameritem.h" 2 | 3 | Q_LOGGING_CATEGORY(M3CORE, "core") 4 | 5 | RenamerItem::RenamerItem(QObject *parent) 6 | : QObject(parent) 7 | { 8 | 9 | } 10 | 11 | void RenamerItem::setOldName(QString name, QString extension) 12 | { 13 | oldNameSplit.first = name; 14 | oldNameSplit.second = extension; 15 | } 16 | 17 | void RenamerItem::setPath(QString path) 18 | { 19 | absolutePath = path; 20 | } 21 | 22 | /** 23 | * @return the absolute path of the item. 24 | */ 25 | QString RenamerItem::path() const 26 | { 27 | return absolutePath; 28 | } 29 | 30 | void RenamerItem::setIsDir(bool isDir) 31 | { 32 | isDirectory = isDir; 33 | } 34 | 35 | bool RenamerItem::isDir() const 36 | { 37 | return isDirectory; 38 | } 39 | 40 | void RenamerItem::setCreated(QDateTime created) 41 | { 42 | this->created = created; 43 | } 44 | 45 | void RenamerItem::setLastModified(QDateTime lastModified) 46 | { 47 | this->lastModified = lastModified; 48 | } 49 | 50 | /** 51 | * @return the previous/current (old) name of the item. 52 | */ 53 | QString RenamerItem::oldName(const bool &absolute) const 54 | { 55 | QString oldName; 56 | if (!oldNameSplit.second.isEmpty()) { 57 | oldName = QString("%1.%2") 58 | .arg(oldNameSplit.first) 59 | .arg(oldNameSplit.second); 60 | } 61 | else { 62 | oldName = oldNameSplit.first; 63 | } 64 | 65 | if (absolute) { 66 | oldName = QString("%1/%2").arg(absolutePath).arg(oldName); 67 | } 68 | return oldName; 69 | } 70 | 71 | /** 72 | * @return the to-be-modified (new) name of the item. 73 | */ 74 | QString RenamerItem::newName(const bool &absolute) const 75 | { 76 | if (newNameSplit.first.isEmpty()) { 77 | return oldName(absolute); 78 | } 79 | QString newName; 80 | if (!newNameSplit.second.isEmpty()) { 81 | newName = QString("%1.%2") 82 | .arg(newNameSplit.first) 83 | .arg(newNameSplit.second); 84 | } 85 | else { 86 | newName = newNameSplit.first; 87 | } 88 | 89 | if (absolute) { 90 | newName = QString("%1/%2").arg(absolutePath).arg(newName); 91 | } 92 | return newName; 93 | } 94 | 95 | bool RenamerItem::isNameChanged() const 96 | { 97 | return nameChanged; 98 | } 99 | 100 | bool RenamerItem::hasWarning() const 101 | { 102 | return false; 103 | } 104 | 105 | bool RenamerItem::hasError() const 106 | { 107 | return false; 108 | } 109 | 110 | bool RenamerItem::applyRenameOps(const int &index, OperationModel* operations) 111 | { 112 | newNameSplit.first.clear(); 113 | newNameSplit.second.clear(); 114 | 115 | newNameSplit = operations->applyOperations(index, oldNameSplit); 116 | 117 | qCDebug(M3CORE) << oldNameSplit.first << oldNameSplit.second 118 | << "=>" << newNameSplit.first << newNameSplit.second; 119 | 120 | nameChanged = (newNameSplit != oldNameSplit); 121 | return nameChanged; 122 | } 123 | 124 | bool RenamerItem::itemCompare(const RenamerItem *i, const RenamerItem *j, Qt::SortOrder order) 125 | { 126 | if (i->isDirectory != j->isDirectory) { 127 | return i->isDirectory; 128 | } 129 | int compare = i->oldName(true).localeAwareCompare(j->oldName(true)); 130 | if (order == Qt::AscendingOrder && compare < 0) { 131 | return true; 132 | } 133 | if (order == Qt::DescendingOrder && compare > 0) { 134 | return true; 135 | } 136 | return false; 137 | } 138 | -------------------------------------------------------------------------------- /src/core/renameritem.h: -------------------------------------------------------------------------------- 1 | #ifndef RENAMERITEM_H 2 | #define RENAMERITEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "operationmodel.h" 10 | 11 | class RenamerItem : public QObject 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit RenamerItem(QObject *parent = 0); 17 | 18 | QString oldName(const bool &absolute = false) const; 19 | QString newName(const bool &absolute = false) const; 20 | bool applyRenameOps(const int &index, 21 | OperationModel* operations); 22 | bool isNameChanged() const; 23 | bool hasWarning() const; 24 | bool hasError() const; 25 | static bool itemCompare(const RenamerItem *i, const RenamerItem *j, 26 | Qt::SortOrder order); 27 | void setOldName(QString name, QString extension); 28 | void setPath(QString path); 29 | QString path() const; 30 | void setIsDir(bool isDir); 31 | bool isDir() const; 32 | void setCreated(QDateTime created); 33 | void setLastModified(QDateTime lastModified); 34 | 35 | private: 36 | std::pair oldNameSplit; 37 | std::pair newNameSplit; 38 | QString absolutePath; 39 | bool nameChanged = false; 40 | int errorCode = 0; 41 | bool isDirectory; 42 | QDateTime created; 43 | QDateTime lastModified; 44 | }; 45 | 46 | #endif // RENAMERITEM_H 47 | -------------------------------------------------------------------------------- /src/core/renamermodel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "renamermodel.h" 4 | #include 5 | 6 | RenamerModel::RenamerModel(QObject *parent) 7 | : QAbstractTableModel(parent) 8 | { 9 | 10 | } 11 | 12 | RenamerModel::~RenamerModel() 13 | { 14 | qDeleteAll(itemsList); 15 | } 16 | 17 | Qt::ItemFlags RenamerModel::flags(const QModelIndex &index) const 18 | { 19 | if (!index.isValid()) { 20 | return Qt::NoItemFlags; 21 | } 22 | return Qt::ItemIsEnabled | Qt::ItemNeverHasChildren | Qt::ItemIsSelectable; 23 | } 24 | 25 | /** 26 | * @return @c true if the model contains no items, @c false otherwise 27 | */ 28 | bool RenamerModel::isEmpty() const 29 | { 30 | return itemsList.isEmpty(); 31 | } 32 | 33 | int RenamerModel::columnCount(const QModelIndex &parent __attribute__ ((unused))) const 34 | { 35 | return 3; 36 | } 37 | 38 | int RenamerModel::rowCount(const QModelIndex &parent __attribute__ ((unused))) const 39 | { 40 | return itemsList.size(); 41 | } 42 | 43 | QVariant RenamerModel::data(const QModelIndex &index, int role) const 44 | { 45 | QVariant data; 46 | if (!index.isValid()) { 47 | return data; 48 | } 49 | if (role == Qt::ToolTipRole) { 50 | RenamerItem *item = itemsList.at(index.row()); 51 | data = item->path(); 52 | } 53 | else if (role == Qt::DisplayRole || role == Qt::EditRole) { 54 | RenamerItem *item = itemsList.at(index.row()); 55 | switch (index.column()) { 56 | case 0: 57 | data = item->path(); 58 | break; 59 | case 1: 60 | data = item->oldName(); 61 | break; 62 | case 2: 63 | data = item->newName(); 64 | break; 65 | default: 66 | break; 67 | } 68 | } 69 | // TODO: there should be no GUI code in this class 70 | else if (role == Qt::BackgroundRole) { 71 | RenamerItem *item = itemsList.at(index.row()); 72 | if (item->hasError()) { 73 | return QBrush(QColor(255, 0, 0, 20)); 74 | } 75 | else if (item->hasWarning()) { 76 | return QBrush(QColor(255, 255, 0, 20)); 77 | } 78 | else if (item->isNameChanged()) { 79 | return QBrush(QColor(0, 255, 0, 10)); 80 | } 81 | } 82 | else if (role == Qt::DecorationRole && index.column() == 0) { 83 | RenamerItem *item = itemsList.at(index.row()); 84 | if (item->isDir()) { 85 | return QIcon::fromTheme("folder"); 86 | } 87 | return QIcon::fromTheme("text-x-generic"); 88 | } 89 | return data; 90 | } 91 | 92 | QVariant RenamerModel::headerData(int section, Qt::Orientation orientation, int role) const 93 | { 94 | if (role != Qt::DisplayRole) { 95 | return QVariant(); 96 | } 97 | if (orientation == Qt::Horizontal) { 98 | QString header; 99 | switch (section) { 100 | case 0: 101 | header = tr("Location"); 102 | break; 103 | case 1: 104 | header = tr("Original Name"); 105 | break; 106 | case 2: 107 | header = tr("New Name"); 108 | break; 109 | default: 110 | break; 111 | } 112 | return header; 113 | } 114 | else if (orientation == Qt::Vertical) { 115 | return locale.toString(section + 1); 116 | } 117 | return QVariant(); 118 | } 119 | 120 | /** 121 | * Removes all items from the model and deletes them. 122 | */ 123 | void RenamerModel::clearAndDelete() 124 | { 125 | if (!itemsList.isEmpty()) { 126 | beginResetModel(); 127 | qCDebug(M3CORE) << "Clearing items..."; 128 | qDeleteAll(itemsList.begin(), itemsList.end()); 129 | itemsList.clear(); 130 | endResetModel(); 131 | } 132 | } 133 | 134 | /** 135 | * Add a list of files to the model. 136 | * @param fileList 137 | * @return the number of files added. 138 | */ 139 | int RenamerModel::addFiles(const QStringList &fileList) 140 | { 141 | int listSize = fileList.size(); 142 | qCDebug(M3CORE) << "Adding" << listSize << "files..."; 143 | 144 | QElapsedTimer timer; 145 | timer.start(); 146 | 147 | int startSize = itemsList.size(); 148 | for (int i = 0; i < listSize; i++) { 149 | addFile(QFileInfo(fileList.at(i))); 150 | } 151 | int endSize = itemsList.size(); 152 | 153 | beginInsertRows(parentItem, startSize, endSize - 1); 154 | endInsertRows(); 155 | 156 | int elapsedTime = timer.elapsed(); 157 | int itemCount = endSize - startSize; 158 | qCDebug(M3CORE) << "Loaded" << itemCount << "items in" << elapsedTime << "msec"; 159 | QString message = tr("Loaded %n item(s)", "", itemCount); 160 | emit operationCompleted(message); 161 | return itemCount; 162 | } 163 | 164 | bool RenamerModel::addFile(const QFileInfo &fileInfo) 165 | { 166 | if (!fileInfo.isWritable()) { 167 | qCWarning(M3CORE) << "Not writable:" << fileInfo.absoluteFilePath(); 168 | return false; 169 | } 170 | RenamerItem *item = new RenamerItem(); 171 | item->setPath(fileInfo.absolutePath()); 172 | item->setOldName(fileInfo.completeBaseName(), fileInfo.completeSuffix()); 173 | item->setIsDir(fileInfo.isDir()); 174 | item->setCreated(fileInfo.created()); 175 | item->setLastModified(fileInfo.lastModified()); 176 | itemsList.append(item); 177 | return true; 178 | } 179 | 180 | int RenamerModel::addDirectories(const QStringList &directoryList, 181 | const bool &recursive, 182 | const QStringList nameFilters, 183 | const bool files, 184 | const bool folders, 185 | const bool hidden) 186 | { 187 | QDir::Filters filter; 188 | if (files) { 189 | filter = QDir::Files; 190 | } 191 | if (folders) { 192 | filter = filter | QDir::Dirs; 193 | } 194 | if (hidden) { 195 | filter = filter | QDir::Hidden; 196 | } 197 | qCDebug(M3CORE) << "Adding" << directoryList.size() << "directories..."; 198 | int itemCount = 0; 199 | for (int i = 0; i < directoryList.size(); i++) { 200 | itemCount += addDirectory(directoryList.at(i), recursive, nameFilters, filter); 201 | } 202 | return itemCount; 203 | } 204 | 205 | int RenamerModel::addDirectory(const QString &path, 206 | const bool recursive, 207 | const QStringList &nameFilters, 208 | const QDir::Filters &filter) 209 | { 210 | QDir dir(path); 211 | if (!dir.exists(path)) { 212 | qCWarning(M3CORE) << QString("Path doesn't exist: %1").arg(path); 213 | return false; 214 | } 215 | dir.setNameFilters(nameFilters); 216 | 217 | dir.setFilter(filter | QDir::NoDotAndDotDot); 218 | 219 | qCDebug(M3CORE) << "Opening:" << path; 220 | 221 | QDirIterator::IteratorFlags flags; 222 | if (recursive) { 223 | flags = QDirIterator::Subdirectories; 224 | } 225 | QDirIterator it (dir, flags); 226 | 227 | QElapsedTimer timer; 228 | timer.start(); 229 | 230 | int startSize = itemsList.size(); 231 | while (it.hasNext()) { 232 | it.next(); 233 | addFile(it.fileInfo()); 234 | } 235 | int endSize = itemsList.size(); 236 | 237 | beginInsertRows(parentItem, startSize, endSize - 1); 238 | endInsertRows(); 239 | 240 | int elapsedTime = timer.elapsed(); 241 | int itemCount = endSize - startSize; 242 | qCDebug(M3CORE) << "Loaded" << itemCount << "items in" << elapsedTime << "msec"; 243 | QString message = QString(tr("Loaded %n item(s)", "", itemCount)); 244 | emit operationCompleted(message); 245 | return itemCount; 246 | } 247 | 248 | bool itemCompareAsc(RenamerItem *i, RenamerItem *j) 249 | { 250 | return RenamerItem::itemCompare(i, j, Qt::AscendingOrder); 251 | } 252 | bool itemCompareDesc(RenamerItem *i, RenamerItem *j) 253 | { 254 | return RenamerItem::itemCompare(i, j, Qt::DescendingOrder); 255 | } 256 | 257 | void RenamerModel::sort(int column, Qt::SortOrder order) 258 | { 259 | int itemCount = rowCount(); 260 | if (itemCount == 0) { 261 | return; 262 | } 263 | 264 | QElapsedTimer timer; 265 | timer.start(); 266 | 267 | int grainsize = std::max(1000, itemCount / 2); 268 | 269 | if (order == Qt::AscendingOrder) { 270 | async_sort(itemsList.begin(), itemCount, grainsize, itemCompareAsc); 271 | } 272 | else { 273 | async_sort(itemsList.begin(), itemCount, grainsize, itemCompareDesc); 274 | } 275 | 276 | int elapsedTime = timer.elapsed(); 277 | emit dataChanged(createIndex(-1,0), createIndex(itemCount,columnCount())); 278 | qCDebug(M3CORE) << "Sorted" << itemCount << "items in" << elapsedTime << "msec"; 279 | QString message = QString(tr("Sorted %n item(s)", "", itemCount)); 280 | emit operationCompleted(message); 281 | } 282 | 283 | void RenamerModel::async_sort(QList::iterator begin, 284 | const int length, const int grainsize, 285 | std::function compareFunction) 286 | { 287 | if (length < grainsize) { 288 | std::sort(begin, begin + length, compareFunction); 289 | } 290 | else { 291 | int half = length/2; 292 | int adjust = length%2; 293 | // call async 294 | std::future future = std::async(std::launch::async, 295 | &RenamerModel::async_sort, this, 296 | begin, half-adjust, grainsize, compareFunction); 297 | // call blocking 298 | async_sort(begin + half, half+adjust, grainsize, compareFunction); 299 | future.wait(); 300 | // merge as we go along 301 | std::inplace_merge(begin, begin + half, begin + length, compareFunction); 302 | } 303 | } 304 | 305 | void RenamerModel::setOperations(OperationModel *operationModel) 306 | { 307 | operations = operationModel; 308 | } 309 | 310 | int RenamerModel::applyRenamingOps() 311 | { 312 | int itemCount = rowCount(); 313 | if (itemCount == 0 || operations->isEmpty()) { 314 | return 0; 315 | } 316 | qCDebug(M3CORE) << "Applying operations on" << itemCount << "items"; 317 | QElapsedTimer timer; 318 | timer.start(); 319 | 320 | // do some pre-processing first... 321 | operations->preProcessOperations(); 322 | 323 | // ...now do the actual operations 324 | int changedCount = 0; 325 | for (int i = 0; i < itemCount; ++i) { 326 | bool nameChanged = itemsList.at(i)->applyRenameOps(i, operations); 327 | if (nameChanged) { 328 | changedCount += 1; 329 | } 330 | } 331 | int elapsedTime = timer.elapsed(); 332 | emit dataChanged(createIndex(-1,0), createIndex(itemCount,columnCount())); 333 | qCDebug(M3CORE) << "Applied rules on" << itemCount << "items in" << elapsedTime << "msec"; 334 | QString message = tr("Applied rules on %n item(s)", "", itemCount); 335 | emit operationCompleted(message); 336 | return changedCount; 337 | } 338 | 339 | int RenamerModel::renameItems() 340 | { 341 | int itemCount = rowCount(); 342 | if (itemCount == 0) { 343 | return 0; 344 | } 345 | qCDebug(M3CORE) << "Renaming" << itemCount << "items"; 346 | QElapsedTimer timer; 347 | timer.start(); 348 | 349 | QDir d; 350 | int renamedCount = 0; 351 | for (int i = 0; i < itemCount; ++i) { 352 | RenamerItem *item = itemsList.at(i); 353 | bool renamed = d.rename(item->oldName(true), item->newName(true)); 354 | if (renamed) { 355 | renamedCount += 1; 356 | } 357 | } 358 | int elapsedTime = timer.elapsed(); 359 | emit dataChanged(createIndex(-1,0), createIndex(itemCount,columnCount())); 360 | qCDebug(M3CORE) << "Renamed" << itemCount << "items in" << elapsedTime << "msec"; 361 | QString message = tr("Renamed %n item(s)", "", itemCount); 362 | emit operationCompleted(message); 363 | return renamedCount; 364 | } 365 | -------------------------------------------------------------------------------- /src/core/renamermodel.h: -------------------------------------------------------------------------------- 1 | #ifndef DIRMODEL 2 | #define DIRMODEL 3 | 4 | #include 5 | #include "renameritem.h" 6 | #include 7 | 8 | 9 | class RenamerModel : public QAbstractTableModel 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | explicit RenamerModel(QObject *parent = 0); 15 | ~RenamerModel(); 16 | 17 | Qt::ItemFlags flags(const QModelIndex &index) const override; 18 | QVariant data(const QModelIndex &index, 19 | int role = Qt::DisplayRole) const override; 20 | QVariant headerData(int section, 21 | Qt::Orientation orientation, 22 | int role = Qt::DisplayRole) const override; 23 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 24 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 25 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override; 26 | void async_sort(QList::iterator begin, const int length, const int grainsize, 27 | std::function compareFunction); 28 | int addDirectories(const QStringList &directoryList, 29 | const bool &recursive, 30 | const QStringList nameFilters, 31 | const bool files, 32 | const bool folders, 33 | const bool hidden); 34 | int addFiles(const QStringList &fileList); 35 | bool isEmpty() const; 36 | int applyRenamingOps(); 37 | int renameItems(); 38 | void setOperations(OperationModel *operationModel); 39 | void clearAndDelete(); 40 | 41 | signals: 42 | void operationCompleted(QString message); 43 | 44 | protected: 45 | QModelIndex parentItem; 46 | bool addFile(const QFileInfo &fileInfo); 47 | int addDirectory(const QString &path, 48 | const bool recursive, 49 | const QStringList &nameFilters, 50 | const QDir::Filters &filter); 51 | 52 | 53 | private: 54 | QList itemsList; 55 | OperationModel* operations; 56 | QLocale locale; 57 | }; 58 | 59 | #endif // DIRMODEL 60 | 61 | -------------------------------------------------------------------------------- /src/image/icon/metamorphose.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/metamorphose/metamorphose3/bc206825d825a40c3b89effdaf780a3759e27a50/src/image/icon/metamorphose.ico -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "mainwindow.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication app(argc, argv); 7 | MainWindow window(new RenamerModel(), new OperationFormModel()); 8 | window.show(); 9 | 10 | return app.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /src/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "mainwindow.h" 5 | #include "ui_mainwindow.h" 6 | 7 | #include "selectionform.h" 8 | #include "ui_selectionform.h" 9 | #include "operationsform.h" 10 | 11 | MainWindow::MainWindow(RenamerModel *renamerModel, 12 | OperationFormModel *operationFormModel, 13 | QWidget *parent) : QMainWindow(parent), 14 | ui(new Ui::MainWindow) 15 | { 16 | this->renamerModel = renamerModel; 17 | connect(renamerModel, SIGNAL(operationCompleted(QString)), 18 | this, SLOT(dirModel_operationCompleted(QString))); 19 | 20 | ui->setupUi(this); 21 | 22 | ui->tableView->setModel(renamerModel); 23 | ui->tableView->resizeColumnsToContents(); 24 | 25 | SelectionForm *selectionForm = new SelectionForm(renamerModel); 26 | connect(selectionForm, SIGNAL(itemsLoaded(int)), 27 | this, SLOT(itemsLoaded(int))); 28 | 29 | ui->mainTabWidget->addTab(selectionForm, tr("Selection")); 30 | 31 | 32 | this->operationFormModel = operationFormModel; 33 | OperationsForm *operationsForm = new OperationsForm(this->operationFormModel); 34 | ui->mainTabWidget->addTab(operationsForm, tr("Renaming")); 35 | 36 | statusBar()->showMessage(tr("Ready")); 37 | } 38 | 39 | MainWindow::~MainWindow() 40 | { 41 | delete ui; 42 | } 43 | 44 | void MainWindow::on_actionQuit_triggered() 45 | { 46 | exit(0); 47 | } 48 | 49 | void MainWindow::on_actionAbout_triggered() 50 | { 51 | QMessageBox aboutBox (this); 52 | aboutBox.setIcon(QMessageBox::Information); 53 | aboutBox.setText("Métamorphose Renamer v3" 54 | "\n\nCopyright © 2015 Ianaré Sévi" 55 | "\n\nMétamorphose is free software: you can redistribute it and/or modify " 56 | "it under the terms of the GNU General Public License as published by " 57 | "the Free Software Foundation, either version 3 of the License, or " 58 | "(at your option) any later version." 59 | "\n\nMétamorphose is distributed in the hope that it will be useful, " 60 | "but WITHOUT ANY WARRANTY; without even the implied warranty of " 61 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 62 | "\nSee the GNU General Public License for more details." 63 | ); 64 | aboutBox.setWindowTitle(tr("About Métamorphose")); 65 | aboutBox.exec(); 66 | } 67 | 68 | void MainWindow::on_previewButton_clicked() 69 | { 70 | renamerModel->setOperations(operationFormModel->getConfiguredOps()); 71 | int changedCount = renamerModel->applyRenamingOps(); 72 | if (changedCount > 0) { 73 | ui->renameButton->setEnabled(true); 74 | } 75 | } 76 | 77 | void MainWindow::on_renameButton_clicked() 78 | { 79 | renamerModel->renameItems(); 80 | } 81 | 82 | void MainWindow::on_clearAllButton_clicked() 83 | { 84 | renamerModel->clearAndDelete(); 85 | ui->tableView->resizeColumnsToContents(); 86 | allowPreview(false); 87 | ui->renameButton->setEnabled(false); 88 | statusBar()->showMessage(tr("Ready")); 89 | } 90 | 91 | void MainWindow::allowPreview(bool allow) const 92 | { 93 | ui->clearAllButton->setEnabled(allow); 94 | ui->previewButton->setEnabled(allow); 95 | } 96 | 97 | void MainWindow::dirModel_operationCompleted(QString message) 98 | { 99 | if (!message.isEmpty()) { 100 | statusBar()->showMessage(message); 101 | } 102 | ui->tableView->resizeColumnsToContents(); 103 | } 104 | 105 | void MainWindow::itemsLoaded(int itemCount) 106 | { 107 | allowPreview((itemCount != 0)); 108 | } 109 | 110 | -------------------------------------------------------------------------------- /src/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "core/renamermodel.h" 7 | #include "operationformmodel.h" 8 | 9 | namespace Ui { 10 | class MainWindow; 11 | } 12 | 13 | class MainWindow : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit MainWindow(RenamerModel *renamerModel, 19 | OperationFormModel *operationFormModel, 20 | QWidget *parent = 0); 21 | ~MainWindow(); 22 | void allowPreview(bool allow) const; 23 | 24 | private slots: 25 | void on_actionQuit_triggered(); 26 | void on_actionAbout_triggered(); 27 | void on_renameButton_clicked(); 28 | void on_previewButton_clicked(); 29 | void on_clearAllButton_clicked(); 30 | void dirModel_operationCompleted(QString message); 31 | void itemsLoaded(int itemCount); 32 | 33 | private: 34 | Ui::MainWindow *ui; 35 | RenamerModel *renamerModel; 36 | OperationFormModel *operationFormModel; 37 | }; 38 | 39 | #endif // MAINWINDOW_H 40 | -------------------------------------------------------------------------------- /src/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 792 10 | 552 11 | 12 | 13 | 14 | Métamorphose 3 15 | 16 | 17 | 18 | :/image/icon/image/icon/metamorphose.ico:/image/icon/image/icon/metamorphose.ico 19 | 20 | 21 | 22 | true 23 | 24 | 25 | 26 | 27 | 28 | 29 | 0 30 | 0 31 | 32 | 33 | 34 | QTabWidget::Rounded 35 | 36 | 37 | -1 38 | 39 | 40 | false 41 | 42 | 43 | false 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | 53 | 16 54 | 55 | 56 | 57 | 58 | false 59 | 60 | 61 | 62 | 0 63 | 0 64 | 65 | 66 | 67 | Preview 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | false 80 | 81 | 82 | Apply renaming operations to disk 83 | 84 | 85 | Rename 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | false 98 | 99 | 100 | Undo 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Qt::Horizontal 113 | 114 | 115 | 116 | 40 117 | 20 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | false 126 | 127 | 128 | Remove all items from the renaming list 129 | 130 | 131 | Clear 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 16 141 | 16 142 | 143 | 144 | 145 | false 146 | 147 | 148 | false 149 | 150 | 151 | false 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | QAbstractScrollArea::AdjustIgnored 161 | 162 | 163 | false 164 | 165 | 166 | false 167 | 168 | 169 | QAbstractItemView::NoDragDrop 170 | 171 | 172 | Qt::MoveAction 173 | 174 | 175 | true 176 | 177 | 178 | QAbstractItemView::ExtendedSelection 179 | 180 | 181 | QAbstractItemView::SelectRows 182 | 183 | 184 | false 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 0 194 | 0 195 | 792 196 | 20 197 | 198 | 199 | 200 | 201 | File 202 | 203 | 204 | 205 | 206 | 207 | Help 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | Exit 223 | 224 | 225 | Ctrl+Q 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | About 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | -------------------------------------------------------------------------------- /src/metamorphose3.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-03-09T11:17:53 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | QMAKE_CXXFLAGS += "-std=c++11" 12 | 13 | TARGET = metamorphose3 14 | TEMPLATE = app 15 | 16 | 17 | SOURCES += main.cpp\ 18 | mainwindow.cpp \ 19 | core/renamermodel.cpp \ 20 | operationsform.cpp \ 21 | operation/insertform.cpp \ 22 | selectionform.cpp \ 23 | core/operationmodel.cpp \ 24 | core/renameritem.cpp \ 25 | core/insertoperation.cpp \ 26 | operationformmodel.cpp \ 27 | suboperationsform.cpp \ 28 | core/operationitem.cpp \ 29 | operationformitem.cpp 30 | 31 | HEADERS += mainwindow.h \ 32 | core/renamermodel.h \ 33 | core/renameritem.h \ 34 | operationsform.h \ 35 | operation/insertform.h \ 36 | selectionform.h \ 37 | core/operationmodel.h \ 38 | core/insertoperation.h \ 39 | operationformmodel.h \ 40 | core/operationitem.h \ 41 | suboperationsform.h \ 42 | operationformitem.h 43 | 44 | FORMS += mainwindow.ui \ 45 | operationsform.ui \ 46 | operation/insertform.ui \ 47 | selectionform.ui \ 48 | suboperationsform.ui \ 49 | operationformitem.ui 50 | 51 | RESOURCES += \ 52 | resources.qrc 53 | -------------------------------------------------------------------------------- /src/operation/insertform.cpp: -------------------------------------------------------------------------------- 1 | #include "operation/insertform.h" 2 | #include "ui_insertform.h" 3 | #include "ui_operationformitem.h" 4 | 5 | InsertForm::InsertForm(QWidget *parent) : 6 | OperationFormItem(parent), 7 | ui(new Ui::InsertForm) 8 | { 9 | qCDebug(M3GUI) << "init InsertForm"; 10 | 11 | insertOperation = new InsertOperation(); 12 | 13 | ui->setupUi(formItemUi->operation); 14 | initSubOperations(ui->toInsert); 15 | 16 | ui->positionSelection->setId(ui->asPrefix, 0); 17 | ui->positionSelection->setId(ui->asSuffix, 1); 18 | ui->positionSelection->setId(ui->atPosition, 2); 19 | ui->positionSelection->setId(ui->beforeText, 3); 20 | ui->positionSelection->setId(ui->afterText, 4); 21 | 22 | connect(ui->positionSelection, SIGNAL(buttonClicked(int)), 23 | this, SLOT(positionSelection_buttonClicked(int))); 24 | connect(ui->toInsert, SIGNAL(selectionChanged()), 25 | this, SLOT(toInsert_selectionChanged())); 26 | connect(ui->toInsert, SIGNAL(textChanged(const QString)), 27 | this, SLOT(toInsert_textChanged(const QString))); 28 | } 29 | 30 | InsertForm::~InsertForm() 31 | { 32 | delete ui; 33 | } 34 | 35 | /** 36 | * Handle enabling the postion spinner. 37 | */ 38 | void InsertForm::positionSelection_buttonClicked(int id) 39 | { 40 | qCDebug(M3GUI) << "positionSelection" << id; 41 | if (id == 2) { 42 | ui->position->setEnabled(true); 43 | } 44 | else { 45 | ui->position->setEnabled(false); 46 | } 47 | if (id == 3 || id == 4) { 48 | ui->toSearch->setEnabled(true); 49 | ui->caseSensitive->setEnabled(true); 50 | } 51 | else { 52 | ui->toSearch->setEnabled(false); 53 | ui->caseSensitive->setEnabled(false); 54 | } 55 | } 56 | 57 | OperationItem* InsertForm::getOperation() 58 | { 59 | return insertOperation; 60 | } 61 | 62 | void InsertForm::configureOperation() 63 | { 64 | insertOperation->setTextToInsert(ui->toInsert->text()); 65 | if (ui->asPrefix->isChecked()) { 66 | insertOperation->setPositionType(InsertOperation::Prefix); 67 | } 68 | else if (ui->asSuffix->isChecked()) { 69 | insertOperation->setPositionType(InsertOperation::Suffix); 70 | } 71 | else if (ui->atPosition->isChecked()) { 72 | insertOperation->setPositionType(InsertOperation::Fixed); 73 | insertOperation->setPosition(ui->position->value()); 74 | } 75 | else if (ui->afterText->isChecked()) { 76 | insertOperation->setPositionType(InsertOperation::AfterText); 77 | insertOperation->setTextToSearch(ui->toSearch->text()); 78 | insertOperation->setCaseSensitive(ui->caseSensitive->isChecked()); 79 | } 80 | else if (ui->beforeText->isChecked()) { 81 | insertOperation->setPositionType(InsertOperation::BeforeText); 82 | insertOperation->setTextToSearch(ui->toSearch->text()); 83 | insertOperation->setCaseSensitive(ui->caseSensitive->isChecked()); 84 | } 85 | insertOperation->setApplyToExtension(applyToExtension); 86 | insertOperation->setApplyToName(applyToName); 87 | } 88 | 89 | QString InsertForm::name() 90 | { 91 | return tr("Insert Operation"); 92 | } 93 | 94 | void InsertForm::toInsert_selectionChanged() 95 | { 96 | qCDebug(M3GUI) << "selection" << ui->toInsert->selectedText(); 97 | } 98 | 99 | void InsertForm::toInsert_textChanged(const QString &arg1) 100 | { 101 | textFormats.clear(); 102 | 103 | // first index all subops start & end positions 104 | QList indexList; 105 | int next = 0; 106 | bool first = true; 107 | while (next > -1) { 108 | // prevents endless loop on finding ":" at first position 109 | if (first) { 110 | next = arg1.indexOf(":", 0); 111 | first = false; 112 | } 113 | else { 114 | next = arg1.indexOf(":", next + 1); 115 | } 116 | if (next > -1) { 117 | indexList << next; 118 | } 119 | } 120 | 121 | // now create format ranges for each subop 122 | for (int i = 0; i < indexList.size(); ++i) { 123 | if (i % 2 == 1) { 124 | QTextLayout::FormatRange subop; 125 | subop.format = defaultSubOpFormat; 126 | subop.start = indexList.at(i - 1); 127 | subop.length = indexList.at(i) - subop.start + 1; 128 | textFormats.append(subop); 129 | } 130 | } 131 | 132 | setLineEditTextFormat(ui->toInsert); 133 | } 134 | -------------------------------------------------------------------------------- /src/operation/insertform.h: -------------------------------------------------------------------------------- 1 | #ifndef INSERTFORM_H 2 | #define INSERTFORM_H 3 | 4 | #include "operationformitem.h" 5 | #include "core/insertoperation.h" 6 | 7 | namespace Ui { 8 | class InsertForm; 9 | } 10 | 11 | class InsertForm : public OperationFormItem 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit InsertForm(QWidget *parent = 0); 17 | ~InsertForm(); 18 | OperationItem* getOperation() override; 19 | void configureOperation() override; 20 | QString name() override; 21 | 22 | private slots: 23 | void positionSelection_buttonClicked(int id); 24 | void toInsert_selectionChanged(); 25 | void toInsert_textChanged(const QString &arg1); 26 | 27 | private: 28 | Ui::InsertForm *ui; 29 | InsertOperation *insertOperation; 30 | }; 31 | 32 | #endif // INSERTFORM_H 33 | -------------------------------------------------------------------------------- /src/operation/insertform.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InsertForm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 512 10 | 139 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 2 28 | 29 | 30 | 31 | 32 | 33 | 0 34 | 0 35 | 36 | 37 | 38 | Insert this: 39 | 40 | 41 | 42 | 43 | 44 | 45 | text or sub-operation 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 0 56 | 0 57 | 58 | 59 | 60 | as a prefix 61 | 62 | 63 | true 64 | 65 | 66 | positionSelection 67 | 68 | 69 | 70 | 71 | 72 | 73 | as a suffix 74 | 75 | 76 | positionSelection 77 | 78 | 79 | 80 | 81 | 82 | 83 | at this position: 84 | 85 | 86 | positionSelection 87 | 88 | 89 | 90 | 91 | 92 | 93 | false 94 | 95 | 96 | 97 | 0 98 | 0 99 | 100 | 101 | 102 | 103 | 70 104 | 0 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | Qt::Horizontal 113 | 114 | 115 | 116 | 40 117 | 20 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 0 128 | 129 | 130 | 131 | 132 | before 133 | 134 | 135 | positionSelection 136 | 137 | 138 | 139 | 140 | 141 | 142 | after 143 | 144 | 145 | positionSelection 146 | 147 | 148 | 149 | 150 | 151 | 152 | this text: 153 | 154 | 155 | 156 | 157 | 158 | 159 | false 160 | 161 | 162 | Blank to insert in between all characters 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | false 172 | 173 | 174 | case sensitive 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /src/operationformitem.cpp: -------------------------------------------------------------------------------- 1 | #include "operationformitem.h" 2 | #include "ui_operationformitem.h" 3 | 4 | OperationFormItem::OperationFormItem(QWidget *parent) : 5 | QWidget(parent), 6 | formItemUi(new Ui::OperationFormItem) 7 | { 8 | qCDebug(M3GUI) << "init OperationFormItem"; 9 | formItemUi->setupUi(this); 10 | 11 | defaultSubOpFormat.setFontWeight(QFont::Bold); 12 | defaultSubOpFormat.setBackground(QColor("#F2F5A9")); 13 | defaultSubOpFormat.setForeground(QColor("#000000")); 14 | } 15 | 16 | void OperationFormItem::initSubOperations(QLineEdit *mainInput) 17 | { 18 | subOperationsForm = new SubOperationsForm(formItemUi->subOperation); 19 | connect(subOperationsForm, SIGNAL(subOperationAdded(QString)), 20 | this, SLOT(insertSubOpText(QString))); 21 | this->mainInput = mainInput; 22 | } 23 | 24 | OperationFormItem::~OperationFormItem() 25 | { 26 | delete formItemUi; 27 | } 28 | 29 | void OperationFormItem::insertSubOpText(QString text) 30 | { 31 | if (mainInput && mainInput->isEnabled()) { 32 | mainInput->insert(text); 33 | mainInput->setFocus(); 34 | return; 35 | } 36 | qCWarning(M3GUI, "Can't insert sub-operation text"); 37 | } 38 | 39 | void OperationFormItem::setLineEditTextFormat(QLineEdit* lineEdit) 40 | { 41 | if(!lineEdit) { 42 | return; 43 | } 44 | 45 | QList attributes; 46 | foreach(const QTextLayout::FormatRange& fr, textFormats) { 47 | QInputMethodEvent::AttributeType type = QInputMethodEvent::TextFormat; 48 | int start = fr.start - lineEdit->cursorPosition(); 49 | int length = fr.length; 50 | QVariant value = fr.format; 51 | attributes.append(QInputMethodEvent::Attribute(type, start, length, value)); 52 | } 53 | QInputMethodEvent event(QString(), attributes); 54 | QCoreApplication::sendEvent(lineEdit, &event); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/operationformitem.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONFORMITEM_H 2 | #define OPERATIONFORMITEM_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "core/operationitem.h" 8 | #include "suboperationsform.h" 9 | 10 | namespace Ui { 11 | class OperationFormItem; 12 | } 13 | 14 | class OperationFormItem : public QWidget 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit OperationFormItem(QWidget *parent = 0); 20 | ~OperationFormItem(); 21 | virtual OperationItem* getOperation() = 0; 22 | virtual void configureOperation() = 0; 23 | virtual QString name() = 0; 24 | void initSubOperations(QLineEdit *mainInput); 25 | bool applyToName = true; 26 | bool applyToExtension = false; 27 | 28 | protected: 29 | void setLineEditTextFormat(QLineEdit* lineEdit); 30 | QList textFormats; 31 | QTextCharFormat defaultSubOpFormat; 32 | SubOperationsForm *subOperationsForm; 33 | Ui::OperationFormItem *formItemUi; 34 | QLineEdit *mainInput = 0; 35 | 36 | private slots: 37 | void insertSubOpText(QString text); 38 | }; 39 | 40 | #endif // OPERATIONFORMITEM_H 41 | -------------------------------------------------------------------------------- /src/operationformitem.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | OperationFormItem 4 | 5 | 6 | 7 | 0 8 | 0 9 | 635 10 | 400 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 0 22 | 200 23 | 24 | 25 | 26 | Qt::NoFocus 27 | 28 | 29 | 30 | 31 | 32 | 33 | 20 34 | 35 | 36 | QLayout::SetDefaultConstraint 37 | 38 | 39 | 0 40 | 41 | 42 | 0 43 | 44 | 45 | 0 46 | 47 | 48 | 0 49 | 50 | 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 0 58 | 0 59 | 60 | 61 | 62 | 63 | 100 64 | 100 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | true 73 | 74 | 75 | 76 | 0 77 | 0 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /src/operationformmodel.cpp: -------------------------------------------------------------------------------- 1 | #include "operationformmodel.h" 2 | 3 | OperationFormModel::OperationFormModel(QObject *parent) 4 | : QAbstractTableModel(parent) 5 | { 6 | operations = new OperationModel(); 7 | } 8 | 9 | OperationFormModel::~OperationFormModel() 10 | { 11 | qDeleteAll(opFormList); 12 | } 13 | 14 | bool OperationFormModel::isEmpty() const 15 | { 16 | return opFormList.isEmpty(); 17 | } 18 | 19 | int OperationFormModel::columnCount(const QModelIndex &parent __attribute__ ((unused))) const 20 | { 21 | return 2; 22 | } 23 | 24 | int OperationFormModel::rowCount(const QModelIndex &parent __attribute__ ((unused))) const 25 | { 26 | return opFormList.size(); 27 | } 28 | 29 | QVariant OperationFormModel::headerData(int section, Qt::Orientation orientation, int role) const 30 | { 31 | if (role != Qt::DisplayRole) { 32 | return QVariant(); 33 | } 34 | if (orientation == Qt::Horizontal) { 35 | QString header; 36 | switch (section) { 37 | case 0: 38 | header = ""; 39 | break; 40 | case 1: 41 | header = tr("Type"); 42 | break; 43 | default: 44 | break; 45 | } 46 | return header; 47 | } 48 | else if (orientation == Qt::Vertical) { 49 | return section + 1; 50 | } 51 | return QVariant(); 52 | } 53 | 54 | QVariant OperationFormModel::data(const QModelIndex &index, int role) const 55 | { 56 | if (!index.isValid()) { 57 | return QVariant(); 58 | } 59 | QVariant data; 60 | if (role == Qt::ToolTipRole) { 61 | data = "tooltip data"; 62 | } 63 | else if (role == Qt::DisplayRole || role == Qt::EditRole) { 64 | OperationFormItem *opForm = opFormList.at(index.row()); 65 | switch (index.column()) { 66 | case 0: 67 | //data = opForm->isEnabled(); 68 | break; 69 | case 1: 70 | data = opForm->name(); 71 | break; 72 | default: 73 | break; 74 | } 75 | } 76 | else if (role == Qt::CheckStateRole && index.column() == 0) { 77 | OperationFormItem *opForm = opFormList.at(index.row()); 78 | if (opForm->isEnabled()) { 79 | data = Qt::Checked; 80 | } 81 | else { 82 | data = Qt::Unchecked; 83 | } 84 | } 85 | return data; 86 | } 87 | 88 | bool OperationFormModel::removeRows(int row, int count, 89 | const QModelIndex &parent) 90 | { 91 | if ((count < 1) || (row < 0) || ((row + count) > rowCount())) { 92 | return false; 93 | } 94 | beginRemoveRows(parentItem, row, row + count - 1); 95 | for (int i = 0; i < count; ++i) { 96 | OperationFormItem *opForm = opFormList.takeAt(row); 97 | qCDebug(M3GUI) << "Remove" << opForm->name() << "at pos" << row + i; 98 | delete opForm; 99 | } 100 | endRemoveRows(); 101 | return true; 102 | } 103 | 104 | bool OperationFormModel::moveRows(const QModelIndex &sourceParent, int sourceRow, 105 | int count, const QModelIndex &destinationParent, 106 | int destinationChild) 107 | { 108 | if (destinationChild == -1) { 109 | return false; 110 | } 111 | int sourceLast = sourceRow + count - 1; 112 | if (destinationChild > sourceLast) { 113 | destinationChild += 1; 114 | } 115 | if (destinationChild > rowCount()) { 116 | return false; 117 | } 118 | bool moveOK = beginMoveRows(sourceParent, sourceRow, sourceLast, 119 | destinationParent, destinationChild); 120 | if (!moveOK) { 121 | return false; 122 | } 123 | 124 | OperationFormItem *opForm = opFormList.takeAt(sourceRow); 125 | opFormList.insert(destinationChild, opForm); 126 | 127 | endMoveRows(); 128 | qCDebug(M3GUI) << "moved" << opForm->name() << "from" << sourceRow << "to" << destinationChild; 129 | return true; 130 | } 131 | 132 | void OperationFormModel::addOperationForm(OperationFormItem *opForm) 133 | { 134 | int size = opFormList.size(); 135 | beginInsertRows(parentItem, size, size); 136 | qCDebug(M3GUI) << "Append" << opForm->name(); 137 | opFormList.append(opForm); 138 | endInsertRows(); 139 | } 140 | 141 | OperationFormItem* OperationFormModel::getOperationAt(int row) 142 | { 143 | return opFormList.at(row); 144 | } 145 | 146 | OperationModel* OperationFormModel::getConfiguredOps() 147 | { 148 | operations->clear(); 149 | qCDebug(M3GUI) << "Configuring" << opFormList.size() << "operation(s)"; 150 | for (OperationFormItem *opForm : opFormList) { 151 | if (opForm->isEnabled()) { 152 | opForm->configureOperation(); 153 | operations->addOperation(opForm->getOperation()); 154 | } 155 | } 156 | return operations; 157 | } 158 | -------------------------------------------------------------------------------- /src/operationformmodel.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONFORMMODEL_H 2 | #define OPERATIONFORMMODEL_H 3 | 4 | #include 5 | #include 6 | #include "operationformitem.h" 7 | #include "core/operationmodel.h" 8 | 9 | class OperationFormModel : public QAbstractTableModel 10 | { 11 | public: 12 | explicit OperationFormModel(QObject *parent = 0); 13 | ~OperationFormModel(); 14 | 15 | QVariant data(const QModelIndex &index, 16 | int role = Qt::DisplayRole) const override; 17 | QVariant headerData(int section, 18 | Qt::Orientation orientation, 19 | int role = Qt::DisplayRole) const override; 20 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; 21 | int columnCount(const QModelIndex &parent = QModelIndex()) const override; 22 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override; 23 | bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, 24 | const QModelIndex &destinationParent, int destinationChild) override; 25 | void addOperationForm(OperationFormItem *opForm); 26 | OperationFormItem* getOperationAt(int row); 27 | OperationModel* getConfiguredOps(); 28 | bool isEmpty() const; 29 | QModelIndex parentItem; 30 | 31 | private: 32 | QList opFormList; 33 | OperationModel *operations; 34 | }; 35 | 36 | #endif // OPERATIONFORMMODEL_H 37 | -------------------------------------------------------------------------------- /src/operationsform.cpp: -------------------------------------------------------------------------------- 1 | #include "operationsform.h" 2 | #include "ui_operationsform.h" 3 | #include "operation/insertform.h" 4 | 5 | OperationsForm::OperationsForm(OperationFormModel *model, QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::OperationsForm) 8 | { 9 | operationFormModel = model; 10 | 11 | ui->setupUi(this); 12 | 13 | ui->operationsTable->setModel(operationFormModel); 14 | ui->operationsTable->resizeColumnsToContents(); 15 | } 16 | 17 | OperationsForm::~OperationsForm() 18 | { 19 | delete ui; 20 | } 21 | 22 | void OperationsForm::on_addOperation_activated(int index) 23 | { 24 | OperationFormItem *opForm; 25 | switch (index) { 26 | case 1: { 27 | opForm = new InsertForm(this); 28 | break; 29 | } 30 | case 2: { 31 | break; 32 | } 33 | case 3: { 34 | break; 35 | } 36 | default: 37 | break; 38 | } 39 | // reset the combo box 40 | ui->addOperation->setCurrentIndex(0); 41 | 42 | // add the operation 43 | operationFormModel->addOperationForm(opForm); 44 | ui->operationsTable->resizeColumnsToContents(); 45 | 46 | int columSpan = ui->gridLayout->columnCount() - 1; 47 | int rowSpan = ui->gridLayout->rowCount() - 1; 48 | ui->gridLayout->addWidget(opForm, 1, 1, rowSpan, columSpan); 49 | 50 | // show the operation 51 | int selectedOp = operationFormModel->rowCount() - 1; 52 | showOperation(selectedOp); 53 | setActionsEnabled(); 54 | } 55 | 56 | void OperationsForm::showOperation(const int row) 57 | { 58 | for (int i = 0; i < operationFormModel->rowCount(); ++i) { 59 | OperationFormItem *opForm = operationFormModel->getOperationAt(i); 60 | opForm->setVisible(false); 61 | } 62 | OperationFormItem *opForm = operationFormModel->getOperationAt(row); 63 | ui->applyToName->setChecked(opForm->applyToName); 64 | ui->applyToExtension->setChecked(opForm->applyToExtension); 65 | opForm->setVisible(true); 66 | 67 | ui->operationsTable->selectRow(row); 68 | } 69 | 70 | void OperationsForm::on_operationsTable_clicked(const QModelIndex &index) 71 | { 72 | int row = index.row(); 73 | showOperation(row); 74 | qCDebug(M3GUI) << "activated operation at row" << row; 75 | } 76 | 77 | void OperationsForm::setActionsEnabled() 78 | { 79 | int opCount = operationFormModel->rowCount(); 80 | bool enable = opCount > 0; 81 | 82 | if (enable && opCount > 1) { 83 | ui->moveOpDown->setEnabled(true); 84 | ui->moveOpUp->setEnabled(true); 85 | } 86 | else { 87 | ui->moveOpDown->setEnabled(false); 88 | ui->moveOpUp->setEnabled(false); 89 | } 90 | // always enable when there are operations 91 | ui->deleteOperation->setEnabled(enable); 92 | ui->applyLabel->setEnabled(enable); 93 | ui->applyToName->setEnabled(enable); 94 | ui->applyToExtension->setEnabled(enable); 95 | 96 | // always enable when there are *no* operations 97 | ui->helpText->setVisible(!enable); 98 | } 99 | 100 | void OperationsForm::on_deleteOperation_activated(const int index) 101 | { 102 | switch (index) { 103 | // delete a single operation 104 | case 0: { 105 | int currentRow = ui->operationsTable->currentIndex().row(); 106 | operationFormModel->removeRows(currentRow, 1); 107 | 108 | // keeping it simple, just show the first operation 109 | if (operationFormModel->rowCount() > 0) { 110 | showOperation(0); 111 | } 112 | break; 113 | } 114 | // delete all operations 115 | case 1: { 116 | operationFormModel->removeRows(0, operationFormModel->rowCount()); 117 | break; 118 | } 119 | default: 120 | break; 121 | } 122 | // reset the combo box 123 | ui->deleteOperation->setCurrentIndex(0); 124 | setActionsEnabled(); 125 | } 126 | 127 | void OperationsForm::on_applyToName_clicked(bool checked) 128 | { 129 | int row = ui->operationsTable->currentIndex().row(); 130 | OperationFormItem *opForm = operationFormModel->getOperationAt(row); 131 | opForm->applyToName = checked; 132 | } 133 | 134 | void OperationsForm::on_applyToExtension_clicked(bool checked) 135 | { 136 | int row = ui->operationsTable->currentIndex().row(); 137 | OperationFormItem *opForm = operationFormModel->getOperationAt(row); 138 | opForm->applyToExtension = checked; 139 | } 140 | 141 | void OperationsForm::on_moveOpUp_clicked() 142 | { 143 | int row = ui->operationsTable->currentIndex().row(); 144 | operationFormModel->moveRow(operationFormModel->parentItem, row, 145 | operationFormModel->parentItem, row - 1); 146 | } 147 | 148 | void OperationsForm::on_moveOpDown_clicked() 149 | { 150 | int row = ui->operationsTable->currentIndex().row(); 151 | operationFormModel->moveRow(operationFormModel->parentItem, row, 152 | operationFormModel->parentItem, row + 1); 153 | } 154 | 155 | -------------------------------------------------------------------------------- /src/operationsform.h: -------------------------------------------------------------------------------- 1 | #ifndef OPERATIONSFORM_H 2 | #define OPERATIONSFORM_H 3 | 4 | #include 5 | #include "operationformmodel.h" 6 | 7 | namespace Ui { 8 | class OperationsForm; 9 | } 10 | 11 | class OperationsForm : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit OperationsForm(OperationFormModel *model, QWidget *parent = 0); 17 | ~OperationsForm(); 18 | 19 | private slots: 20 | void on_addOperation_activated(int index); 21 | void on_operationsTable_clicked(const QModelIndex &index); 22 | void on_deleteOperation_activated(const int index); 23 | void on_applyToName_clicked(bool checked); 24 | void on_applyToExtension_clicked(bool checked); 25 | void on_moveOpUp_clicked(); 26 | void on_moveOpDown_clicked(); 27 | 28 | private: 29 | void showOperation(const int row); 30 | void setActionsEnabled(); 31 | 32 | Ui::OperationsForm *ui; 33 | OperationFormModel *operationFormModel; 34 | }; 35 | 36 | #endif // OPERATIONSFORM_H 37 | -------------------------------------------------------------------------------- /src/operationsform.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | OperationsForm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 767 10 | 207 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | QLayout::SetDefaultConstraint 19 | 20 | 21 | 22 | 23 | false 24 | 25 | 26 | name 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | false 37 | 38 | 39 | Apply to: 40 | 41 | 42 | 25 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 0 51 | 0 52 | 53 | 54 | 55 | 56 | Add Operation 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Insert 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | false 75 | 76 | 77 | ... 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | false 90 | 91 | 92 | ... 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | Qt::Horizontal 105 | 106 | 107 | 108 | 40 109 | 20 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | false 118 | 119 | 120 | extension 121 | 122 | 123 | 124 | 125 | 126 | 127 | false 128 | 129 | 130 | 131 | Delete 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | Delete All 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 0 156 | 0 157 | 158 | 159 | 160 | 161 | 200 162 | 16777215 163 | 164 | 165 | 166 | true 167 | 168 | 169 | QAbstractItemView::SingleSelection 170 | 171 | 172 | QAbstractItemView::SelectRows 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 0 181 | 0 182 | 183 | 184 | 185 | 186 | 0 187 | 0 188 | 189 | 190 | 191 | 192 | 75 193 | true 194 | 195 | 196 | 197 | QFrame::NoFrame 198 | 199 | 200 | You don't have any operations defined. 201 | 202 | 203 | Qt::AlignCenter 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /src/resources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | image/icon/metamorphose.ico 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/selectionform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "selectionform.h" 4 | #include "ui_selectionform.h" 5 | 6 | SelectionForm::SelectionForm(RenamerModel *model, QWidget *parent) : 7 | QWidget(parent), 8 | ui(new Ui::SelectionForm) 9 | { 10 | renamerModel = model; 11 | ui->setupUi(this); 12 | } 13 | 14 | SelectionForm::~SelectionForm() 15 | { 16 | delete ui; 17 | } 18 | 19 | void SelectionForm::on_addDirButton_clicked() 20 | { 21 | QFileDialog dialog(this); 22 | dialog.setFileMode(QFileDialog::Directory); 23 | dialog.setOptions(QFileDialog::ReadOnly 24 | | QFileDialog::ShowDirsOnly 25 | | QFileDialog::DontResolveSymlinks); 26 | if (dialog.exec()) { 27 | int itemCount; 28 | itemCount = renamerModel->addDirectories(dialog.selectedFiles(), 29 | ui->addRecursive->isChecked(), 30 | ui->filterNames->text().split(" "), 31 | ui->filterIncludeFiles->isChecked(), 32 | ui->filterIncludeDirs->isChecked(), 33 | ui->filterIncludeHidden->isChecked() 34 | ); 35 | emit itemsLoaded(itemCount); 36 | } 37 | } 38 | 39 | void SelectionForm::on_addFilesButton_clicked() 40 | { 41 | QFileDialog dialog(this); 42 | dialog.setFileMode(QFileDialog::ExistingFiles); 43 | dialog.setOptions(QFileDialog::ReadOnly 44 | | QFileDialog::DontResolveSymlinks); 45 | dialog.setNameFilter(ui->filterNames->text()); 46 | if (dialog.exec()) { 47 | int itemCount = renamerModel->addFiles(dialog.selectedFiles()); 48 | emit itemsLoaded(itemCount); 49 | } 50 | } 51 | 52 | void SelectionForm::on_sortButton_clicked() 53 | { 54 | Qt::SortOrder order; 55 | if (ui->sortAscending->isChecked()) { 56 | order = Qt::AscendingOrder; 57 | } 58 | else { 59 | order = Qt::DescendingOrder; 60 | } 61 | renamerModel->sort(0, order); 62 | } 63 | -------------------------------------------------------------------------------- /src/selectionform.h: -------------------------------------------------------------------------------- 1 | #ifndef SELECTIONFORM_H 2 | #define SELECTIONFORM_H 3 | 4 | #include 5 | #include "core/renamermodel.h" 6 | 7 | namespace Ui { 8 | class SelectionForm; 9 | } 10 | 11 | class SelectionForm : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit SelectionForm(RenamerModel *model, QWidget *parent = 0); 17 | ~SelectionForm(); 18 | 19 | signals: 20 | void itemsLoaded(int itemCount); 21 | 22 | private: 23 | Ui::SelectionForm *ui; 24 | RenamerModel* renamerModel; 25 | 26 | private slots: 27 | void on_addDirButton_clicked(); 28 | void on_addFilesButton_clicked(); 29 | void on_sortButton_clicked(); 30 | }; 31 | 32 | #endif // SELECTIONFORM_H 33 | -------------------------------------------------------------------------------- /src/selectionform.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SelectionForm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 593 10 | 212 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 2 18 | 19 | 20 | 21 | 22 | 10 23 | 140 24 | 278 25 | 31 26 | 27 | 28 | 29 | 30 | 31 | 32 | Sort 33 | 34 | 35 | false 36 | 37 | 38 | 39 | 40 | 41 | 42 | Ascending 43 | 44 | 45 | true 46 | 47 | 48 | 49 | 50 | 51 | 52 | Descending 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 10 62 | 60 63 | 440 64 | 33 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | 73 | 74 | Add individual files 75 | 76 | 77 | Add Files 78 | 79 | 80 | 81 | 82 | 83 | 84 | or 85 | 86 | 87 | 8 88 | 89 | 90 | 91 | 92 | 93 | 94 | Add directory contents 95 | 96 | 97 | Add Directory 98 | 99 | 100 | 101 | 102 | 103 | 104 | true 105 | 106 | 107 | Files 108 | 109 | 110 | true 111 | 112 | 113 | 114 | 115 | 116 | 117 | true 118 | 119 | 120 | Folders 121 | 122 | 123 | false 124 | 125 | 126 | 127 | 128 | 129 | 130 | Recursive 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 10 140 | 20 141 | 261 142 | 31 143 | 144 | 145 | 146 | 147 | 148 | 149 | Filters: 150 | 151 | 152 | 153 | 154 | 155 | 156 | Space separated list of filters 157 | 158 | 159 | * 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | Hidden 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /src/selectwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selectwidget.h" 2 | #include "ui_selectwidget.h" 3 | 4 | SelectWidget::SelectWidget(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::SelectWidget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SelectWidget::~SelectWidget() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /src/suboperationsform.cpp: -------------------------------------------------------------------------------- 1 | #include "suboperationsform.h" 2 | #include "ui_suboperationsform.h" 3 | 4 | Q_LOGGING_CATEGORY(M3GUI, "gui") 5 | 6 | SubOperationsForm::SubOperationsForm(QWidget *parent) : 7 | QWidget(parent), 8 | ui(new Ui::SubOperationsForm) 9 | { 10 | ui->setupUi(this); 11 | } 12 | 13 | SubOperationsForm::~SubOperationsForm() 14 | { 15 | delete ui; 16 | } 17 | 18 | void SubOperationsForm::on_numberingButton_clicked() 19 | { 20 | emit subOperationAdded(":numb:"); 21 | } 22 | 23 | void SubOperationsForm::on_dateButton_clicked() 24 | { 25 | emit subOperationAdded(":date:"); 26 | } 27 | 28 | void SubOperationsForm::on_timeButton_clicked() 29 | { 30 | emit subOperationAdded(":time:"); 31 | } 32 | -------------------------------------------------------------------------------- /src/suboperationsform.h: -------------------------------------------------------------------------------- 1 | #ifndef SUBOPERATIONSFORM_H 2 | #define SUBOPERATIONSFORM_H 3 | 4 | #include 5 | #include 6 | 7 | Q_DECLARE_LOGGING_CATEGORY(M3GUI) 8 | 9 | namespace Ui { 10 | class SubOperationsForm; 11 | } 12 | 13 | class SubOperationsForm : public QWidget 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit SubOperationsForm(QWidget *parent = 0); 19 | ~SubOperationsForm(); 20 | 21 | signals: 22 | void subOperationAdded(QString operation); 23 | 24 | private slots: 25 | void on_numberingButton_clicked(); 26 | void on_dateButton_clicked(); 27 | void on_timeButton_clicked(); 28 | 29 | private: 30 | Ui::SubOperationsForm *ui; 31 | }; 32 | 33 | #endif // SUBOPERATIONSFORM_H 34 | -------------------------------------------------------------------------------- /src/suboperationsform.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SubOperationsForm 4 | 5 | 6 | 7 | 0 8 | 0 9 | 617 10 | 44 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | Form 21 | 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 0 31 | 32 | 33 | 0 34 | 35 | 36 | 37 | 38 | Qt::Horizontal 39 | 40 | 41 | 42 | 40 43 | 20 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | Add a sub-operation: 52 | 53 | 54 | 55 | 56 | 57 | 58 | time 59 | 60 | 61 | 62 | 63 | 64 | 65 | Add an numbering sequence. 66 | 67 | 68 | numbering 69 | 70 | 71 | 72 | 73 | 74 | 75 | date 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | --------------------------------------------------------------------------------