generic: move sub-projects from kde-baseapps [ci reset]

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-05-14 21:28:45 +03:00
parent 00cf2c8af7
commit f68295ea28
1670 changed files with 410980 additions and 15 deletions

View file

@ -7,6 +7,8 @@ include(GenerateExportHeader)
find_package(KDE4 4.22.0 REQUIRED) find_package(KDE4 4.22.0 REQUIRED)
include(KDE4Defaults) include(KDE4Defaults)
set(LIBRARY_TYPE SHARED)
find_package(ZLIB) find_package(ZLIB)
set_package_properties(ZLIB PROPERTIES set_package_properties(ZLIB PROPERTIES
DESCRIPTION "Support for gzip compressed files and data streams" DESCRIPTION "Support for gzip compressed files and data streams"
@ -30,6 +32,14 @@ set_package_properties(SharedMimeInfo PROPERTIES
TYPE REQUIRED TYPE REQUIRED
) )
find_package(Sudo)
set_package_properties(Sudo PROPERTIES
DESCRIPTION "Sudo allows a system administrator to delegate authority to give certain users"
URL "https://www.sudo.ws/"
TYPE RUNTIME
PURPOSE "Needed for kdesudo to operate"
)
if(Q_WS_X11) if(Q_WS_X11)
find_package(XCB REQUIRED) find_package(XCB REQUIRED)
set_package_properties(XCB PROPERTIES set_package_properties(XCB PROPERTIES
@ -120,14 +130,6 @@ set_package_properties(Fontconfig PROPERTIES
TYPE OPTIONAL TYPE OPTIONAL
) )
macro_optional_find_package(LibKonq)
set_package_properties(LibKonq PROPERTIES
DESCRIPTION "Konqueror library"
URL "http://fluxer.github.io/katana/"
PURPOSE "folderview plasma applets"
TYPE OPTIONAL
)
macro_optional_find_package(LibUSB) macro_optional_find_package(LibUSB)
set_package_properties(LibUSB PROPERTIES set_package_properties(LibUSB PROPERTIES
DESCRIPTION "User level access to USB devices" DESCRIPTION "User level access to USB devices"
@ -272,6 +274,30 @@ add_feature_info(gdb_or_lldb
"Backtraces support" "Backtraces support"
) )
find_program(CTAGS_EXECUTABLE ctags ctags-universal ctags-exuberant exctags uctags)
add_feature_info(ctags
CTAGS_EXECUTABLE
"Code indexing support in Kate"
)
find_program(CPPCHECK_EXECUTABLE cppcheck)
add_feature_info(cppcheck
CPPCHECK_EXECUTABLE
"Code analysis support in Kate"
)
find_program(RZSZ_EXECUTABLE NAMES rz lrz)
add_feature_info(rzsz
RZSZ_EXECUTABLE
"ZModem support in Konsole"
)
find_program(LOCALE_EXECUTABLE NAMES locate)
add_feature_info(locate
LOCALE_EXECUTABLE
"Search indexing support in KFind"
)
check_include_files(sys/wait.h HAVE_SYS_WAIT_H) check_include_files(sys/wait.h HAVE_SYS_WAIT_H)
check_include_files(sys/time.h HAVE_SYS_TIME_H) check_include_files(sys/time.h HAVE_SYS_TIME_H)
@ -346,6 +372,16 @@ add_subdirectory(kquitapp)
if (Q_WS_X11) if (Q_WS_X11)
add_subdirectory(kstart) add_subdirectory(kstart)
endif (Q_WS_X11) endif (Q_WS_X11)
# imported from kde-baseapps
add_subdirectory(dolphin)
add_subdirectory(kate)
add_subdirectory(kdepasswd)
add_subdirectory(kdesudo)
add_subdirectory(kdialog)
add_subdirectory(keditbookmarks)
add_subdirectory(kfind)
add_subdirectory(kmediaplayer)
add_subdirectory(konsole)
# Background processes # Background processes
add_subdirectory(kdontchangethehostname) add_subdirectory(kdontchangethehostname)
add_subdirectory(kglobalaccel) add_subdirectory(kglobalaccel)

View file

@ -26,7 +26,8 @@ build_script:
libglu1-mesa-dev mesa-common-dev libmtp-dev libusb-1.0-0-dev libssh-dev \ libglu1-mesa-dev mesa-common-dev libmtp-dev libusb-1.0-0-dev libssh-dev \
libsmbclient-dev libdrm-dev libraw1394-dev libsensors4-dev \ libsmbclient-dev libdrm-dev libraw1394-dev libsensors4-dev \
libegl-dev libpci-dev libopenexr-dev liblzma-dev libbz2-dev libgphoto2-dev \ libegl-dev libpci-dev libopenexr-dev liblzma-dev libbz2-dev libgphoto2-dev \
liblightdm-gobject-1-dev libkmod-dev libdbusmenu-katie ccache liblightdm-gobject-1-dev libkmod-dev libdbusmenu-katie \
sudo ctags cppcheck lrzsz locate ccache
export PATH="/usr/lib/ccache/:$PATH" export PATH="/usr/lib/ccache/:$PATH"

6
dolphin/AUTHORS Normal file
View file

@ -0,0 +1,6 @@
Peter Penz <peter.penz@gmx.at>
David Faure <faure@kde.org>
Aaron J. Seigo <aseigo@kde.org>
Rafael Fernández López <ereslibre@kde.org>
Kevin Ottens <ervin@kde.org>
Holger Freyther <freyther@gmx.net>

13
dolphin/CMakeLists.txt Normal file
View file

@ -0,0 +1,13 @@
include(CheckStructHasMember)
check_struct_has_member("struct dirent" d_type dirent.h HAVE_DIRENT_D_TYPE)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config-dolphin.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config-dolphin.h
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(src)
add_subdirectory(plugins)

346
dolphin/COPYING Normal file
View file

@ -0,0 +1,346 @@
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
the instance of code that it refers to (the kde programs) are copyrighted
by the authors who actually wrote it.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

397
dolphin/COPYING.DOC Normal file
View file

@ -0,0 +1,397 @@
GNU Free Documentation License
Version 1.2, November 2002
Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
0. PREAMBLE
The purpose of this License is to make a manual, textbook, or other
functional and useful document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.
This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense. It
complements the GNU General Public License, which is a copyleft
license designed for free software.
We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does. But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book. We recommend this License
principally for works whose purpose is instruction or reference.
1. APPLICABILITY AND DEFINITIONS
This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License. Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein. The "Document", below,
refers to any such manual or work. Any member of the public is a
licensee, and is addressed as "you". You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.
A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.
A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject. (Thus, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.) The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.
The "Invariant Sections" are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License. If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant. The Document may contain zero
Invariant Sections. If the Document does not identify any Invariant
Sections then there are none.
The "Cover Texts" are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License. A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.
A "Transparent" copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters. A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text. A copy that is not "Transparent" is called "Opaque".
Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML, PostScript or PDF designed for human modification. Examples of
transparent image formats include PNG, XCF and JPG. Opaque formats
include proprietary formats that can be read and edited only by
proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML, PostScript or PDF produced by some word
processors for output purposes only.
The "Title Page" means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page. For works in
formats which do not have any title page as such, "Title Page" means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.
A section "Entitled XYZ" means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language. (Here XYZ stands for a
specific section name mentioned below, such as "Acknowledgements",
"Dedications", "Endorsements", or "History".) To "Preserve the Title"
of such a section when you modify the Document means that it remains a
section "Entitled XYZ" according to this definition.
The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document. These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.
2. VERBATIM COPYING
You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License. You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough
number of copies you must also follow the conditions in section 3.
You may also lend copies, under the same conditions stated above, and
you may publicly display copies.
3. COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover. Both covers must also clearly and legibly identify
you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and
visible. You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.
If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.
It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.
4. MODIFICATIONS
You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it. In addition, you must do these things in the Modified Version:
A. Use in the Title Page (and on the covers, if any) a title distinct
from that of the Document, and from those of previous versions
(which should, if there were any, be listed in the History section
of the Document). You may use the same title as a previous version
if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities
responsible for authorship of the modifications in the Modified
Version, together with at least five of the principal authors of the
Document (all of its principal authors, if it has fewer than five),
unless they release you from this requirement.
C. State on the Title page the name of the publisher of the
Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications
adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice
giving the public permission to use the Modified Version under the
terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections
and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled "History", Preserve its Title, and add
to it an item stating at least the title, year, new authors, and
publisher of the Modified Version as given on the Title Page. If
there is no section Entitled "History" in the Document, create one
stating the title, year, authors, and publisher of the Document as
given on its Title Page, then add an item describing the Modified
Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for
public access to a Transparent copy of the Document, and likewise
the network locations given in the Document for previous versions
it was based on. These may be placed in the "History" section.
You may omit a network location for a work that was published at
least four years before the Document itself, or if the original
publisher of the version it refers to gives permission.
K. For any section Entitled "Acknowledgements" or "Dedications",
Preserve the Title of the section, and preserve in the section all
the substance and tone of each of the contributor acknowledgements
and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document,
unaltered in their text and in their titles. Section numbers
or the equivalent are not considered part of the section titles.
M. Delete any section Entitled "Endorsements". Such a section
may not be included in the Modified Version.
N. Do not retitle any existing section to be Entitled "Endorsements"
or to conflict in title with any Invariant Section.
O. Preserve any Warranty Disclaimers.
If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant. To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.
You may add a section Entitled "Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.
You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version. Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity. If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.
The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.
The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy. If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled "History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled "Acknowledgements",
and any sections Entitled "Dedications". You must delete all sections
Entitled "Endorsements".
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.
You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.
7. AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an "aggregate" if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.
8. TRANSLATION
Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections. You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers. In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.
If a section in the Document is Entitled "Acknowledgements",
"Dedications", or "History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.
9. TERMINATION
You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License. Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License. However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.
10. FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. See
http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation. If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
ADDENDUM: How to use this License for your documents
To use this License in a document you have written, include a copy of
the License in the document and put the following copyright and
license notices just after the title page:
Copyright (c) YEAR YOUR NAME.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
replace the "with...Texts." line with this:
with the Invariant Sections being LIST THEIR TITLES, with the
Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST.
If you have Invariant Sections without Cover Texts, or some other
combination of the three, merge those two alternatives to suit the
situation.
If your document contains nontrivial examples of program code, we
recommend releasing these examples in parallel under your choice of
free software license, such as the GNU General Public License,
to permit their use in free software.

2
dolphin/README Normal file
View file

@ -0,0 +1,2 @@
See http://dolphin.kde.org for information about Dolphin.

View file

@ -0,0 +1,4 @@
/* config.h. Generated by cmake from config.h.cmake */
/* Defined to 1 if you have a d_type member in struct dirent */
#cmakedefine HAVE_DIRENT_D_TYPE 1

View file

@ -0,0 +1,10 @@
include_directories(
${CMAKE_SOURCE_DIR}/libs/konq
${CMAKE_BINARY_DIR}/libs/konq
)
add_subdirectory(svn)
add_subdirectory(git)
add_subdirectory(hg)
add_subdirectory(bazaar)
add_subdirectory(dropbox)

346
dolphin/plugins/COPYING Normal file
View file

@ -0,0 +1,346 @@
NOTE! The GPL below is copyrighted by the Free Software Foundation, but
the instance of code that it refers to (the kde programs) are copyrighted
by the authors who actually wrote it.
---------------------------------------------------------------------------
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View file

@ -0,0 +1,16 @@
project(fileviewbazaarplugin)
kde4_add_plugin(fileviewbazaarplugin fileviewbazaarplugin.cpp)
target_link_libraries(fileviewbazaarplugin ${KDE4_KIO_LIBS} konq)
install(
FILES
fileviewbazaarplugin.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
TARGETS fileviewbazaarplugin
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)

View file

@ -0,0 +1,2 @@
#! /bin/sh
$XGETTEXT *.cpp -o $podir/fileviewbazaarplugin.pot

View file

@ -0,0 +1,464 @@
/***************************************************************************
* Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2011 Canonical Ltd. *
* By Jonathan Riddell <jriddell@ubuntu.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "fileviewbazaarplugin.h"
#include <kaction.h>
#include <kdialog.h>
#include <kdebug.h>
#include <kfileitem.h>
#include <kicon.h>
#include <klocale.h>
#include <krun.h>
#include <kshell.h>
#include <kvbox.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <QDir>
#include <QLabel>
#include <QPlainTextEdit>
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QTextStream>
K_PLUGIN_FACTORY(FileViewBazaarPluginFactory,registerPlugin<FileViewBazaarPlugin>();)
K_EXPORT_PLUGIN(FileViewBazaarPluginFactory("fileviewbazaarplugin"))
FileViewBazaarPlugin::FileViewBazaarPlugin(QObject* parent, const QList<QVariant>& args) :
KVersionControlPlugin(parent),
m_pendingOperation(false),
m_versionInfoHash(),
m_updateAction(0),
m_pullAction(0),
m_pushAction(0),
m_showLocalChangesAction(0),
m_commitAction(0),
m_addAction(0),
m_removeAction(0),
m_logAction(0),
m_command(),
m_arguments(),
m_errorMsg(),
m_operationCompletedMsg(),
m_contextDir(),
m_contextItems(),
m_process(),
m_tempFile()
{
Q_UNUSED(args);
m_updateAction = new KAction(this);
m_updateAction->setIcon(KIcon("go-down"));
m_updateAction->setText(i18nc("@item:inmenu", "Bazaar Update"));
connect(m_updateAction, SIGNAL(triggered()),
this, SLOT(updateFiles()));
m_pullAction = new KAction(this);
m_pullAction->setIcon(KIcon("go-bottom"));
m_pullAction->setText(i18nc("@item:inmenu", "Bazaar Pull"));
connect(m_pullAction, SIGNAL(triggered()),
this, SLOT(pullFiles()));
m_pushAction = new KAction(this);
m_pushAction->setIcon(KIcon("go-top"));
m_pushAction->setText(i18nc("@item:inmenu", "Bazaar Push"));
connect(m_pushAction, SIGNAL(triggered()),
this, SLOT(pushFiles()));
m_showLocalChangesAction = new KAction(this);
m_showLocalChangesAction->setIcon(KIcon("view-split-left-right"));
m_showLocalChangesAction->setText(i18nc("@item:inmenu", "Show Local Bazaar Changes"));
connect(m_showLocalChangesAction, SIGNAL(triggered()),
this, SLOT(showLocalChanges()));
m_commitAction = new KAction(this);
m_commitAction->setIcon(KIcon("svn-commit"));
m_commitAction->setText(i18nc("@item:inmenu", "Bazaar Commit..."));
connect(m_commitAction, SIGNAL(triggered()),
this, SLOT(commitFiles()));
m_addAction = new KAction(this);
m_addAction->setIcon(KIcon("list-add"));
m_addAction->setText(i18nc("@item:inmenu", "Bazaar Add..."));
connect(m_addAction, SIGNAL(triggered()),
this, SLOT(addFiles()));
m_removeAction = new KAction(this);
m_removeAction->setIcon(KIcon("list-remove"));
m_removeAction->setText(i18nc("@item:inmenu", "Bazaar Delete"));
connect(m_removeAction, SIGNAL(triggered()),
this, SLOT(removeFiles()));
m_logAction = new KAction(this);
m_logAction->setIcon(KIcon("format-list-ordered"));
m_logAction->setText(i18nc("@item:inmenu", "Bazaar Log"));
connect(m_logAction, SIGNAL(triggered()),
this, SLOT(log()));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotOperationError()));
}
FileViewBazaarPlugin::~FileViewBazaarPlugin()
{
}
QString FileViewBazaarPlugin::fileName() const
{
return QLatin1String(".bzr");
}
bool FileViewBazaarPlugin::beginRetrieval(const QString& directory)
{
Q_ASSERT(directory.endsWith(QLatin1Char('/')));
QString baseDir;
QProcess process1;
process1.setWorkingDirectory(directory);
process1.start(QLatin1String("bzr root"));
while (process1.waitForReadyRead()) {
char buffer[512];
while (process1.readLine(buffer, sizeof(buffer)) > 0) {
baseDir = QString(buffer).trimmed();
}
}
// if bzr is not installed
if (baseDir == "") {
return false;
}
// Clear all entries for this directory including the entries
// for sub directories
QMutableHashIterator<QString, ItemVersion> it(m_versionInfoHash);
while (it.hasNext()) {
it.next();
if (it.key().startsWith(directory) || !it.key().startsWith(baseDir)) {
it.remove();
}
}
QProcess process2;
process2.setWorkingDirectory(directory);
process2.start(QLatin1String("bzr ignored"));
while (process2.waitForReadyRead()) {
char buffer[512];
while (process2.readLine(buffer, sizeof(buffer)) > 0) {
QString line = QString(buffer).trimmed();
QStringList list = line.split(" ");
QString file = baseDir + "/" + list[0];
m_versionInfoHash.insert(file, UnversionedVersion);
}
}
QStringList arguments;
arguments << QLatin1String("status") << QLatin1String("-S");
arguments << baseDir;
QProcess process;
process.start(QLatin1String("bzr"), arguments);
while (process.waitForReadyRead()) {
char buffer[1024];
while (process.readLine(buffer, sizeof(buffer)) > 0) {
ItemVersion state = NormalVersion;
QString filePath = QString::fromUtf8(buffer);
// This could probably do with being more consistent
switch (buffer[0]) {
case '?': state = UnversionedVersion; break;
case ' ': if (buffer[1] == 'M') {state = LocallyModifiedVersion;} break;
case '+': state = AddedVersion; break;
case '-': state = RemovedVersion; break;
case 'C': state = ConflictingVersion; break;
default:
if (filePath.contains('*')) {
state = UpdateRequiredVersion;
}
break;
}
// Only values with a different state as 'NormalVersion'
// are added to the hash table. If a value is not in the
// hash table, it is automatically defined as 'NormalVersion'
// (see FileViewBazaarPlugin::itemVersion()).
if (state != NormalVersion) {
int pos = 4;
const int length = filePath.length() - pos - 1;
//conflicts annoyingly have a human readable text before the filename
//TODO cover other conflict types
if (filePath.startsWith("C Text conflict")) {
filePath = filePath.mid(17, length);
}
filePath = baseDir + "/" + filePath.mid(pos, length);
//remove type symbols from directories, links and executables
if (filePath.endsWith("/") || filePath.endsWith("@") || filePath.endsWith("*")) {
filePath = filePath.left(filePath.length() - 1);
}
if (!filePath.isEmpty()) {
m_versionInfoHash.insert(filePath, state);
}
}
}
}
if ((process.exitCode() != 0 || process.exitStatus() != QProcess::NormalExit)) {
return false;
}
return true;
}
void FileViewBazaarPlugin::endRetrieval()
{
}
KVersionControlPlugin::ItemVersion FileViewBazaarPlugin::itemVersion(const KFileItem& item) const
{
const QString itemUrl = item.localPath();
if (m_versionInfoHash.contains(itemUrl)) {
return m_versionInfoHash.value(itemUrl);
}
if (!item.isDir()) {
// files that have not been listed by 'bzr status' or 'bzr ignored' (= m_versionInfoHash)
// are under version control per definition
return NormalVersion;
}
// The item is a directory. Check whether an item listed by 'bzr status' (= m_versionInfoHash)
// is part of this directory. In this case a local modification should be indicated in the
// directory already.
QHash<QString, ItemVersion>::const_iterator it = m_versionInfoHash.constBegin();
while (it != m_versionInfoHash.constEnd()) {
if (it.key().startsWith(itemUrl)) {
const ItemVersion state = m_versionInfoHash.value(it.key());
if (state == LocallyModifiedVersion) {
return LocallyModifiedVersion;
}
}
++it;
}
return NormalVersion;
}
QList<QAction*> FileViewBazaarPlugin::actions(const KFileItemList& items) const
{
Q_ASSERT(!items.isEmpty());
foreach (const KFileItem& item, items) {
m_contextItems.append(item);
}
m_contextDir.clear();
const bool noPendingOperation = !m_pendingOperation;
if (noPendingOperation) {
// iterate all items and check the version state to know which
// actions can be enabled
const int itemsCount = items.count();
int versionedCount = 0;
int editingCount = 0;
foreach (const KFileItem& item, items) {
const ItemVersion state = itemVersion(item);
if (state != UnversionedVersion) {
++versionedCount;
}
switch (state) {
case LocallyModifiedVersion:
case ConflictingVersion:
++editingCount;
break;
default:
break;
}
}
m_commitAction->setEnabled(editingCount > 0);
m_addAction->setEnabled(versionedCount == 0);
m_removeAction->setEnabled(versionedCount == itemsCount);
} else {
m_commitAction->setEnabled(false);
m_addAction->setEnabled(false);
m_removeAction->setEnabled(false);
}
m_updateAction->setEnabled(noPendingOperation);
m_pullAction->setEnabled(noPendingOperation);
m_pushAction->setEnabled(noPendingOperation);
m_showLocalChangesAction->setEnabled(noPendingOperation);
m_logAction->setEnabled(noPendingOperation);
QList<QAction*> actions;
actions.append(m_updateAction);
actions.append(m_pullAction);
actions.append(m_pushAction);
actions.append(m_commitAction);
actions.append(m_addAction);
actions.append(m_removeAction);
actions.append(m_showLocalChangesAction);
actions.append(m_logAction);
return actions;
}
void FileViewBazaarPlugin::updateFiles()
{
execBazaarCommand("qupdate", QStringList(),
i18nc("@info:status", "Updating Bazaar repository..."),
i18nc("@info:status", "Update of Bazaar repository failed."),
i18nc("@info:status", "Updated Bazaar repository."));
}
void FileViewBazaarPlugin::pullFiles()
{
QStringList arguments = QStringList();
arguments << "-d";
execBazaarCommand("qpull", arguments,
i18nc("@info:status", "Pulling Bazaar repository..."),
i18nc("@info:status", "Pull of Bazaar repository failed."),
i18nc("@info:status", "Pulled Bazaar repository."));
}
void FileViewBazaarPlugin::pushFiles()
{
QStringList arguments = QStringList();
arguments << "-d";
execBazaarCommand("qpush", arguments,
i18nc("@info:status", "Pushing Bazaar repository..."),
i18nc("@info:status", "Push of Bazaar repository failed."),
i18nc("@info:status", "Pushed Bazaar repository."));
}
void FileViewBazaarPlugin::showLocalChanges()
{
execBazaarCommand("qdiff", QStringList(),
i18nc("@info:status", "Reviewing Changes..."),
i18nc("@info:status", "Review Changes failed."),
i18nc("@info:status", "Reviewed Changes."));
}
void FileViewBazaarPlugin::commitFiles()
{
execBazaarCommand("qcommit", QStringList(),
i18nc("@info:status", "Committing Bazaar changes..."),
i18nc("@info:status", "Commit of Bazaar changes failed."),
i18nc("@info:status", "Committed Bazaar changes."));
}
void FileViewBazaarPlugin::addFiles()
{
execBazaarCommand(QLatin1String("qadd"), QStringList(),
i18nc("@info:status", "Adding files to Bazaar repository..."),
i18nc("@info:status", "Adding of files to Bazaar repository failed."),
i18nc("@info:status", "Added files to Bazaar repository."));
}
void FileViewBazaarPlugin::removeFiles()
{
execBazaarCommand(QLatin1String("remove"), QStringList(),
i18nc("@info:status", "Removing files from Bazaar repository..."),
i18nc("@info:status", "Removing of files from Bazaar repository failed."),
i18nc("@info:status", "Removed files from Bazaar repository."));
}
void FileViewBazaarPlugin::log()
{
execBazaarCommand(QLatin1String("qlog"), QStringList(),
i18nc("@info:status", "Running Bazaar Log..."),
i18nc("@info:status", "Running Bazaar Log failed."),
i18nc("@info:status", "Bazaar Log closed."));
}
void FileViewBazaarPlugin::slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus)
{
m_pendingOperation = false;
if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
emit errorMessage(m_errorMsg);
} else if (m_contextItems.isEmpty()) {
emit operationCompletedMessage(m_operationCompletedMsg);
emit itemVersionsChanged();
} else {
startBazaarCommandProcess();
}
}
void FileViewBazaarPlugin::slotOperationError()
{
// don't do any operation on other items anymore
m_contextItems.clear();
m_pendingOperation = false;
emit errorMessage(m_errorMsg);
}
void FileViewBazaarPlugin::execBazaarCommand(const QString& command,
const QStringList& arguments,
const QString& infoMsg,
const QString& errorMsg,
const QString& operationCompletedMsg)
{
emit infoMessage(infoMsg);
QProcess process;
process.start(QLatin1String("bzr plugins"));
bool foundQbzr = false;
while (process.waitForReadyRead()) {
char buffer[512];
while (process.readLine(buffer, sizeof(buffer)) > 0) {
QString output = QString(buffer).trimmed();
if (output.startsWith("qbzr")) {
foundQbzr = true;
break;
}
}
}
if (!foundQbzr) {
emit infoMessage("Please Install QBzr");
return;
}
m_command = command;
m_arguments = arguments;
m_errorMsg = errorMsg;
m_operationCompletedMsg = operationCompletedMsg;
startBazaarCommandProcess();
}
void FileViewBazaarPlugin::startBazaarCommandProcess()
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
m_pendingOperation = true;
const QString program(QLatin1String("bzr"));
QStringList arguments;
arguments << m_command << m_arguments;
if (!m_contextDir.isEmpty()) {
arguments << m_contextDir;
m_contextDir.clear();
} else {
const KFileItem item = m_contextItems.takeLast();
arguments << item.localPath();
// the remaining items of m_contextItems will be executed
// after the process has finished (see slotOperationFinished())
}
m_process.start(program, arguments);
}

View file

@ -0,0 +1,48 @@
[Desktop Entry]
Type=Service
Name=Bazaar
Name[ar]=Bazaar
Name[bs]=Bazaar
Name[ca]=Bazaar
Name[ca@valencia]=Bazaar
Name[cs]=Bazaar
Name[da]=Bazaar
Name[de]=Bazaar
Name[el]=Bazaar
Name[en_GB]=Bazaar
Name[es]=Bazaar
Name[et]=Bazaar
Name[fi]=Bazaar
Name[fr]=Bazaar
Name[gl]=Bazaar
Name[hu]=Bazaar
Name[it]=Bazaar
Name[kk]=Bazaar
Name[ko]=Bazaar
Name[lt]=Bazaar
Name[mr]=
Name[nb]=Bazaar
Name[nds]=Bazaar
Name[nl]=Bazaar
Name[pa]=
Name[pl]=Bazaar
Name[pt]=Bazaar
Name[pt_BR]=Bazaar
Name[ro]=Bazaar
Name[ru]=Bazaar
Name[sk]=Bazaar
Name[sl]=Bazaar
Name[sr]=Базар
Name[sr@ijekavian]=Базар
Name[sr@ijekavianlatin]=Bazaar
Name[sr@latin]=Bazaar
Name[sv]=Bazaar
Name[tr]=Bazaar
Name[ug]=Bazaar
Name[uk]=Bazaar
Name[x-test]=xxBazaarxx
Name[zh_CN]=Bazaar
Name[zh_TW]=Bazaar
X-KDE-ServiceTypes=FileViewVersionControlPlugin
MimeType=text/plain;
X-KDE-Library=fileviewbazaarplugin

View file

@ -0,0 +1,104 @@
/***************************************************************************
* Copyright (C) 2009-2010 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2011 Canonical Ltd. *
* By Jonathan Riddell <jriddell@ubuntu.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef FILEVIEWBAZAARPLUGIN_H
#define FILEVIEWBAZAARPLUGIN_H
#include <kfileitem.h>
#include <kversioncontrolplugin.h>
#include <QHash>
#include <QProcess>
#include <QTemporaryFile>
/**
* @brief Bazaar (bzr) implementation for the KVersionControlPlugin interface.
*/
class FileViewBazaarPlugin : public KVersionControlPlugin
{
Q_OBJECT
public:
FileViewBazaarPlugin(QObject* parent, const QList<QVariant>& args);
virtual ~FileViewBazaarPlugin();
virtual QString fileName() const;
virtual bool beginRetrieval(const QString& directory);
virtual void endRetrieval();
virtual KVersionControlPlugin::ItemVersion itemVersion(const KFileItem& item) const;
virtual QList<QAction*> actions(const KFileItemList& items) const;
private slots:
void updateFiles();
void pullFiles();
void pushFiles();
void showLocalChanges();
void commitFiles();
void addFiles();
void removeFiles();
void log();
void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
void slotOperationError();
private:
/**
* Executes the command "bzr {bzrCommand}" for the files that have been
* set by getting the context menu actions (see contextMenuActions()).
* @param infoMsg Message that should be shown before the command is executed.
* @param errorMsg Message that should be shown if the execution of the command
* has been failed.
* @param operationCompletedMsg
* Message that should be shown if the execution of the command
* has been completed successfully.
*/
void execBazaarCommand(const QString& bzrCommand,
const QStringList& arguments,
const QString& infoMsg,
const QString& errorMsg,
const QString& operationCompletedMsg);
void startBazaarCommandProcess();
private:
bool m_pendingOperation;
QHash<QString, ItemVersion> m_versionInfoHash;
QAction* m_updateAction;
QAction* m_pullAction;
QAction* m_pushAction;
QAction* m_showLocalChangesAction;
QAction* m_commitAction;
QAction* m_addAction;
QAction* m_removeAction;
QAction* m_logAction;
QString m_command;
QStringList m_arguments;
QString m_errorMsg;
QString m_operationCompletedMsg;
mutable QString m_contextDir;
mutable KFileItemList m_contextItems;
QProcess m_process;
QTemporaryFile m_tempFile;
};
#endif // FILEVIEWBAZAARPLUGIN_H

View file

@ -0,0 +1,15 @@
project(fileviewdropboxplugin)
kde4_add_plugin(fileviewdropboxplugin fileviewdropboxplugin.cpp)
target_link_libraries(fileviewdropboxplugin ${KDE4_KIO_LIBS} konq)
install(
FILES fileviewdropboxplugin.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
TARGETS fileviewdropboxplugin
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)

View file

@ -0,0 +1,222 @@
/*****************************************************************************
* Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
* Copyright (C) 2012 by Sergei Stolyarov <sergei@regolit.com> *
* Copyright (C) 2010 by Thomas Richard <thomas.richard@proan.be> *
* Copyright (C) 2009-2010 by Peter Penz <peter.penz19@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
*****************************************************************************/
#include <KAction>
#include <KFileItem>
#include <KFileItemListProperties>
#include <KLocalizedString>
#include <KActionCollection>
#include <KPluginFactory>
#include <KIcon>
#include <QDir>
#include <QPointer>
#include <QLocalSocket>
#include <QFileSystemWatcher>
#include "fileviewdropboxplugin.h"
K_PLUGIN_FACTORY(FileViewDropboxPluginFactory, registerPlugin<FileViewDropboxPlugin>();)
K_EXPORT_PLUGIN(FileViewDropboxPluginFactory("fileviewdropboxplugin"))
class FileViewDropboxPlugin::Private
{
public:
Private(FileViewDropboxPlugin* parent) :
contextFilePaths(),
controlSocketPath(),
controlSocket(new QLocalSocket(parent)),
databaseFileWatcher(new QFileSystemWatcher(parent)),
contextActions(new KActionCollection(parent))
{
}
QStringList contextFilePaths;
QString controlSocketPath;
QPointer<QLocalSocket> controlSocket;
QPointer<QLocalSocket> itemStateSocket;
QPointer<QFileSystemWatcher> databaseFileWatcher;
QPointer<KActionCollection> contextActions;
};
QMap<QString, KVersionControlPlugin::ItemVersion> FileViewDropboxPlugin::m_itemVersions;
FileViewDropboxPlugin::FileViewDropboxPlugin(QObject* parent, const QVariantList& args):
KVersionControlPlugin(parent),
d(new Private(this))
{
Q_UNUSED(args);
if (m_itemVersions.isEmpty()) {
m_itemVersions.insert("up to date", KVersionControlPlugin::NormalVersion);
m_itemVersions.insert("syncing", KVersionControlPlugin::UpdateRequiredVersion);
m_itemVersions.insert("unsyncable", KVersionControlPlugin::ConflictingVersion);
m_itemVersions.insert("unwatched", KVersionControlPlugin::UnversionedVersion);
}
const QString dropboxDir = QDir::home().path() + QDir::separator() + fileName() + QDir::separator();
d->controlSocketPath = QDir::toNativeSeparators(dropboxDir + QLatin1String("command_socket"));
d->controlSocket->connectToServer(d->controlSocketPath);
connect(d->databaseFileWatcher, SIGNAL(fileChanged(QString)), SIGNAL(itemVersionsChanged()));
d->databaseFileWatcher->addPath(QDir::toNativeSeparators(dropboxDir + QLatin1String("aggregation.dbx")));
connect(d->contextActions, SIGNAL(actionTriggered(QAction*)), SLOT(handleContextAction(QAction*)));
}
FileViewDropboxPlugin::~FileViewDropboxPlugin()
{
delete d;
}
QString FileViewDropboxPlugin::fileName() const
{
return QLatin1String(".dropbox");
}
bool FileViewDropboxPlugin::beginRetrieval(const QString& directory)
{
Q_UNUSED(directory);
Q_ASSERT(directory.endsWith(QLatin1Char('/')));
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError");
qRegisterMetaType<QAbstractSocket::SocketState>("QAbstractSocket::SocketState");
d->itemStateSocket = new QLocalSocket;
return connectWithDropbox(d->itemStateSocket, LongTimeout);
}
KVersionControlPlugin::ItemVersion FileViewDropboxPlugin::itemVersion(const KFileItem& item) const
{
const QStringList reply = sendCommand("icon_overlay_file_status\npath\t", QStringList() << QDir(item.localPath()).canonicalPath(),
d->itemStateSocket, WaitForReply, LongTimeout);
if(reply.count() < 2) {
// file/dir is not served by dropbox
return KVersionControlPlugin::UnversionedVersion;
}
return m_itemVersions.value(reply.at(1), KVersionControlPlugin::UnversionedVersion);
}
void FileViewDropboxPlugin::endRetrieval()
{
delete d->itemStateSocket;
}
QList<QAction*> FileViewDropboxPlugin::actions(const KFileItemList& items) const
{
Q_ASSERT(!items.isEmpty());
d->contextActions->clear();
d->contextFilePaths.clear();
const KFileItemListProperties properties(items);
if (!properties.isLocal()) {
// not all files/dirs are local files/dirs
return QList<QAction*>();
}
foreach (const KFileItem& item, items) {
d->contextFilePaths << QDir(item.localPath()).canonicalPath();
}
const QStringList reply = sendCommand("icon_overlay_context_options\npaths\t", d->contextFilePaths, d->controlSocket, WaitForReply);
if (reply.count() < 2) {
// files/dirs are not served by dropbox
return QList<QAction*>();
}
// analyze item options and dynamically form a menu
foreach (const QString& replyLine, reply) {
const QStringList options = replyLine.split("~");
if (options.count() > 2) {
KAction* action = d->contextActions->addAction(options.at(2));
action->setText(options.at(0));
action->setToolTip(options.at(1));
action->setIcon(KIcon("dropbox"));
}
}
return d->contextActions->actions();
}
void FileViewDropboxPlugin::handleContextAction(QAction* action)
{
sendCommand("icon_overlay_context_action\nverb\t" + action->objectName() + "\npaths\t", d->contextFilePaths, d->controlSocket);
}
QStringList FileViewDropboxPlugin::sendCommand(const QString& command,
const QStringList& paths,
const QPointer<QLocalSocket>& socket,
SendCommandMode mode,
SendCommandTimeout timeout) const
{
if (!connectWithDropbox(socket, timeout)) {
return QStringList();
}
static const QString parameterSeperator('\t');
static const QString done("\ndone\n");
static const QString ok("ok\n");
const QString request = command + paths.join(parameterSeperator) + done;
socket->readAll();
socket->write(request.toUtf8());
socket->flush();
if (mode == SendCommandOnly) {
return QStringList();
}
QString reply;
while (socket->waitForReadyRead(timeout == ShortTimeout ? 100 : 500)) {
reply.append(QString::fromUtf8(socket->readAll()));
if (reply.endsWith(done)) {
break;
}
}
reply.remove(done);
reply.remove(ok);
return reply.split(parameterSeperator, QString::SkipEmptyParts);
}
bool FileViewDropboxPlugin::connectWithDropbox(const QPointer<QLocalSocket>& socket, SendCommandTimeout timeout) const
{
if (socket->state() != QLocalSocket::ConnectedState) {
socket->connectToServer(d->controlSocketPath);
if (!socket->waitForConnected(timeout == ShortTimeout ? 100 : 500)) {
socket->abort();
return false;
}
}
return true;
}
#include "moc_fileviewdropboxplugin.cpp"

View file

@ -0,0 +1,39 @@
[Desktop Entry]
Type=Service
Name=Dropbox
Name[ar]=Dropbox
Name[ca]=Dropbox
Name[ca@valencia]=Dropbox
Name[da]=Dropbox
Name[de]=Dropbox
Name[el]=Dropbox
Name[en_GB]=Dropbox
Name[es]=Dropbox
Name[et]=Dropbox
Name[fi]=Dropbox
Name[fr]=DropBox
Name[hu]=Dropbox
Name[it]=Dropbox
Name[ko]=Dropbox
Name[lt]=Dropbox
Name[nb]=Dropbox
Name[nl]=Dropbox
Name[pl]=Dropbox
Name[pt]=Dropbox
Name[pt_BR]=Dropbox
Name[ro]=Dropbox
Name[ru]=Dropbox
Name[sk]=Dropbox
Name[sl]=Dropbox
Name[sr]=Дропбокс
Name[sr@ijekavian]=Дропбокс
Name[sr@ijekavianlatin]=Dropbox
Name[sr@latin]=Dropbox
Name[sv]=Dropbox
Name[tr]=Dropbox
Name[uk]=Dropbox
Name[x-test]=xxDropboxxx
Name[zh_TW]=Dropbox
X-KDE-ServiceTypes=FileViewVersionControlPlugin
MimeType=text/plain;
X-KDE-Library=fileviewdropboxplugin

View file

@ -0,0 +1,90 @@
/*****************************************************************************
* Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
* Copyright (C) 2012 by Sergei Stolyarov <sergei@regolit.com> *
* Copyright (C) 2010 by Thomas Richard <thomas.richard@proan.be> *
* Copyright (C) 2009-2010 by Peter Penz <peter.penz19@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
*****************************************************************************/
#ifndef FILEVIEWDROPBOXPLUGIN_H
#define FILEVIEWDROPBOXPLUGIN_H
#include <kversioncontrolplugin.h>
#include <QMap>
#include <QtCore/qvariant.h>
#include <QPointer>
#include <QLocalSocket>
//The dropbox protocol info can be found in the dropboxd-protocol file
//it can be found here http://dl.dropbox.com/u/4577542/dropbox/dropboxd-protocol.txt
//Thanks Steffen Schuldenzucker!
/**
* @brief Dropbox implementation for the KVersionControlPlugin interface.
*/
class FileViewDropboxPlugin : public KVersionControlPlugin
{
Q_OBJECT
private:
enum SendCommandMode
{
WaitForReply,
SendCommandOnly
};
enum SendCommandTimeout
{
ShortTimeout,
LongTimeout
};
public:
FileViewDropboxPlugin(QObject* parent, const QVariantList& args);
virtual ~FileViewDropboxPlugin();
virtual QString fileName() const;
virtual bool beginRetrieval(const QString& directory);
virtual KVersionControlPlugin::ItemVersion itemVersion(const KFileItem& item) const;
virtual void endRetrieval();
virtual QList<QAction*> actions(const KFileItemList& items) const;
private slots:
void handleContextAction(QAction* action);
private:
QStringList sendCommand(const QString& command,
const QStringList& paths,
const QPointer<QLocalSocket>& socket,
SendCommandMode mode = SendCommandOnly,
SendCommandTimeout timeout = ShortTimeout) const;
bool connectWithDropbox(const QPointer<QLocalSocket>& socket, SendCommandTimeout timeout) const;
private:
class Private;
Private* const d;
static QMap<QString, KVersionControlPlugin::ItemVersion> m_itemVersions;
};
#endif // FILEVIEWDROPBOXPLUGIN_H

View file

@ -0,0 +1,32 @@
project(fileviewgitplugin)
set(fileviewgitplugin_SRCS
fileviewgitplugin.cpp
checkoutdialog.cpp
commitdialog.cpp
tagdialog.cpp
pushdialog.cpp
pulldialog.cpp
gitwrapper.cpp
)
kde4_add_kcfg_files(fileviewgitplugin_SRCS fileviewgitpluginsettings.kcfgc)
kde4_add_plugin(fileviewgitplugin ${fileviewgitplugin_SRCS})
target_link_libraries(fileviewgitplugin ${KDE4_KIO_LIBS} konq)
install(
FILES fileviewgitplugin.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
FILES fileviewgitpluginsettings.kcfg
DESTINATION ${KDE4_KCFG_INSTALL_DIR}
)
install(
TARGETS fileviewgitplugin
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)

View file

@ -0,0 +1,3 @@
#! /bin/sh
$EXTRACTRC *.kcfg >> rc.cpp
$XGETTEXT *.cpp -o $podir/fileviewgitplugin.pot

View file

@ -0,0 +1,256 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "checkoutdialog.h"
#include "gitwrapper.h"
#include <kcombobox.h>
#include <kdialog.h>
#include <klineedit.h>
#include <klocale.h>
#include <kvbox.h>
#include <QCheckBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QRadioButton>
#include <QString>
CheckoutDialog::CheckoutDialog(QWidget* parent):
KDialog(parent, Qt::Dialog),
m_userEditedNewBranchName(false)
{
//branch/tag selection
this->setCaption(i18nc("@title:window", "<application>Git</application> Checkout"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Checkout"));
KVBox * vbox = new KVBox(this);
this->setMainWidget(vbox);
m_branchSelectGroupBox = new QGroupBox(vbox);
QGridLayout * gridLayout = new QGridLayout(m_branchSelectGroupBox);
m_branchSelectGroupBox->setLayout(gridLayout);
m_branchRadioButton = new QRadioButton(i18nc("@option:radio Git Checkout","Branch:"), m_branchSelectGroupBox);
m_branchRadioButton->setChecked(true);
gridLayout->addWidget(m_branchRadioButton,0,0);
m_branchRadioButton->setFocus();
m_branchComboBox = new KComboBox(false, m_branchSelectGroupBox);
gridLayout->addWidget(m_branchComboBox,0,1);
QRadioButton * tagRadioButton = new QRadioButton(i18nc("@option:radio Git Checkout", "Tag:"), m_branchSelectGroupBox);
gridLayout->addWidget(tagRadioButton,1,0);
m_tagComboBox = new KComboBox(false, m_branchSelectGroupBox);
m_tagComboBox->setEnabled(false);
gridLayout->addWidget(m_tagComboBox,1,1);
//options
QGroupBox * optionsGroupBox = new QGroupBox(vbox);
optionsGroupBox->setTitle(i18nc("@title:group", "Options"));
QGridLayout * optionsGridLayout = new QGridLayout(optionsGroupBox);
optionsGroupBox->setLayout(optionsGridLayout);
m_newBranchCheckBox = new QCheckBox(i18nc("@option:check", "Create New Branch: "), optionsGroupBox);
m_newBranchCheckBox->setToolTip(i18nc("@info:tooltip", "Create a new branch based on a selected branch or tag."));
optionsGridLayout->addWidget(m_newBranchCheckBox, 0,0);
m_newBranchName = new KLineEdit(optionsGroupBox);
m_newBranchName->setMinimumWidth(150);
m_newBranchName->setClearButtonShown(true);
optionsGridLayout->addWidget(m_newBranchName, 0, 1);
//initialize alternate color scheme for errors
m_errorColors = m_newBranchName->palette();
m_errorColors.setColor(QPalette::Normal, QPalette::Base, Qt::red);
m_errorColors.setColor(QPalette::Inactive, QPalette::Base, Qt::red);
m_forceCheckBox = new QCheckBox(i18nc("@option:check", "Force"), optionsGroupBox);
m_forceCheckBox->setToolTip(i18nc("@info:tooltip", "Discard local changes."));
optionsGridLayout->addWidget(m_forceCheckBox, 1,0);
//get branch names
GitWrapper * gitWrapper = GitWrapper::instance();
int currentBranchIndex;
const QStringList branches = gitWrapper->branches(&currentBranchIndex);
m_branchComboBox->addItems(branches);
if (currentBranchIndex == -1) {
m_branchComboBox->insertItem(0, "(no branch)");
m_branchComboBox->setCurrentIndex(0);
} else {
m_branchComboBox->setCurrentIndex(currentBranchIndex);
}
setDefaultNewBranchName(m_branchComboBox->currentText());
//keep local branches to prevent creating an equally named new branch
foreach (const QString& b, branches) {
if (!b.startsWith(QLatin1String("remotes/"))) {
//you CAN create local branches called "remotes/...", but since no sane person
//would do that, we save the effort of another call to "git branch"
m_branchNames.insert(b);
}
}
//get tag names
const QStringList tags = gitWrapper->tags();
m_tagComboBox->addItems(tags);
m_tagComboBox->setCurrentIndex(m_tagComboBox->count()-1);
if (m_tagComboBox->count() == 0){
tagRadioButton->setEnabled(false);
const QString tooltip = i18nc("@info:tooltip", "There are no tags in this repository.");
tagRadioButton->setToolTip(tooltip);
m_tagComboBox->setToolTip(tooltip);
}
//signals
connect(m_branchRadioButton, SIGNAL(toggled(bool)),
this, SLOT(branchRadioButtonToggled(bool)));
connect(m_branchComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setDefaultNewBranchName(QString)));
connect(m_branchComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setOkButtonState()));
connect(m_tagComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(setDefaultNewBranchName(QString)));
connect(m_newBranchCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(newBranchCheckBoxStateToggled(int)));
connect(m_newBranchName, SIGNAL(textChanged(QString)),
this, SLOT(setOkButtonState()));
connect(m_newBranchName, SIGNAL(textEdited(QString)),
this, SLOT(noteUserEditedNewBranchName()));
//set initial widget states
newBranchCheckBoxStateToggled(Qt::Unchecked);
}
QString CheckoutDialog::checkoutIdentifier() const
{
QString identifier = m_branchComboBox->isEnabled() ? m_branchComboBox->currentText() : m_tagComboBox->currentText();
if (identifier.length()==0 || identifier.at(0)=='(') {
identifier = "";
}
return identifier;
}
bool CheckoutDialog::force() const
{
return m_forceCheckBox->isChecked();
}
QString CheckoutDialog::newBranchName() const
{
if (m_newBranchCheckBox->isChecked()) {
return m_newBranchName->text().trimmed();
} else {
return QString();
}
}
void CheckoutDialog::branchRadioButtonToggled(bool checked)
{
m_branchComboBox->setEnabled(checked);
m_tagComboBox->setEnabled(!checked);
setDefaultNewBranchName(checked ? m_branchComboBox->currentText() : m_tagComboBox->currentText());
setOkButtonState();
}
void CheckoutDialog::newBranchCheckBoxStateToggled(int state)
{
m_newBranchName->setEnabled(state == Qt::Checked);
m_branchSelectGroupBox->setTitle(
state == Qt::Checked ?
i18nc("@title:group", "Branch Base") :
i18nc("@title:group", "Checkout"));
if (state == Qt::Checked) {
m_newBranchName->setFocus(Qt::TabFocusReason);
}
setOkButtonState();
}
void CheckoutDialog::setOkButtonState()
{
//default to enabled
bool enableButton = true;
bool newNameError = false;
//------------disable on these conditions---------------//
if (m_newBranchCheckBox->isChecked()) {
const QString newBranchName = m_newBranchName->text().trimmed();
if (newBranchName.isEmpty()){
enableButton = false;
newNameError = true;
const QString tt = i18nc("@info:tooltip", "You must enter a valid name for the new branch first.");
m_newBranchName->setToolTip(tt);
this->setButtonToolTip(KDialog::Ok, tt);
}
if (m_branchNames.contains(newBranchName)) {
enableButton = false;
newNameError = true;
const QString tt = i18nc("@info:tooltip", "A branch with the name '%1' already exists.", newBranchName);
m_newBranchName->setToolTip(tt);
this->setButtonToolTip(KDialog::Ok, tt);
}
if (newBranchName.contains(QRegExp("\\s"))) {
enableButton = false;
newNameError = true;
const QString tt = i18nc("@info:tooltip", "Branch names may not contain any whitespace.");
m_newBranchName->setToolTip(tt);
this->setButtonToolTip(KDialog::Ok, tt);
}
} //if we create a new branch and no valid branch is selected we create one based on the currently checked out version
else if (m_branchRadioButton->isChecked() && m_branchComboBox->currentText().at(0) == '('){
enableButton = false;
this->setButtonToolTip(KDialog::Ok, i18nc("@info:tooltip", "You must select a valid branch first."));
}
//------------------------------------------------------//
setLineEditErrorModeActive(newNameError);
this->enableButtonOk(enableButton);
if (!newNameError) {
m_newBranchName->setToolTip(QString());
}
if (enableButton) {
this->setButtonToolTip(KDialog::Ok, QString());
}
}
void CheckoutDialog::setDefaultNewBranchName(const QString& baseBranchName)
{
if (!m_userEditedNewBranchName) {
if (baseBranchName.startsWith('(')) {
m_newBranchName->setText("");
} else {
m_newBranchName->setText(i18nc("@item:intext Prepended to the current branch name "
"to get the default name for a newly created branch", "branch") + '_' + baseBranchName);
}
}
}
void CheckoutDialog::noteUserEditedNewBranchName()
{
m_userEditedNewBranchName = true;
}
void CheckoutDialog::setLineEditErrorModeActive(bool active)
{
m_newBranchName->setPalette(active ? m_errorColors : QPalette());
}
#include "moc_checkoutdialog.cpp"

View file

@ -0,0 +1,88 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef CHECKOUTDIALOG_H
#define CHECKOUTDIALOG_H
#include <kdialog.h>
#include <QSet>
#include <QString>
class KComboBox;
class KLineEdit;
#include <QCheckBox>
#include <QGroupBox>
#include <QRadioButton>
/**
* @brief The dialog for checking out Branches or Tags in Git.
*/
class CheckoutDialog : public KDialog
{
Q_OBJECT
public:
CheckoutDialog(QWidget* parent = 0);
/**
* Returns the name of the selected tag or branch to be checkout out
* @returns The name of the selected tag or branch
*/
QString checkoutIdentifier() const;
/**
* @returns True if the user selected a forced checkout, false otherwise.
*/
bool force() const;
/**
* @returns The user selected name of the new branch, if a new branch is to be
* created, empty String otherwise.
*/
QString newBranchName() const;
private slots:
void branchRadioButtonToggled(bool checked);
void newBranchCheckBoxStateToggled(int state);
/**
* Checks whether the values of all relevant widgets are valid.
* Enables or disables the OK button and sets tooltips accordingly.
*/
void setOkButtonState();
void noteUserEditedNewBranchName();
/**
* Inserts a default name for the new branch into m_newBranchName unless the user
* has already edited the content.
* @param baseBranchName The base name to derive the new name of.
*/
void setDefaultNewBranchName(const QString & baseBranchName);
private:
inline void setLineEditErrorModeActive(bool active);
private:
///@brief true if the user has manually edited the branchName, false otherwise
bool m_userEditedNewBranchName;
QSet<QString> m_branchNames;
QPalette m_errorColors;
QGroupBox * m_branchSelectGroupBox;
QRadioButton * m_branchRadioButton;
KComboBox * m_branchComboBox;
KComboBox * m_tagComboBox;
QCheckBox * m_newBranchCheckBox;
KLineEdit * m_newBranchName;
QCheckBox * m_forceCheckBox;
};
#endif // CHECKOUTDIALOG_H

View file

@ -0,0 +1,134 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "commitdialog.h"
#include "fileviewgitpluginsettings.h"
#include "gitwrapper.h"
#include <klocale.h>
#include <ktextedit.h>
#include <kvbox.h>
#include <QGroupBox>
#include <QCheckBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QTextCodec>
CommitDialog::CommitDialog (QWidget* parent ):
KDialog (parent, Qt::Dialog),
m_localCodec(QTextCodec::codecForLocale())
{
this->setCaption(i18nc("@title:window", "<application>Git</application> Commit"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Commit"));
KVBox* vbox = new KVBox(this);
this->setMainWidget(vbox);
QGroupBox* messageGroupBox = new QGroupBox(vbox);
messageGroupBox->setTitle(i18nc("@title:group", "Commit message"));
QVBoxLayout * messageVBox = new QVBoxLayout(messageGroupBox);
messageGroupBox->setLayout(messageVBox);
m_commitMessageTextEdit = new KTextEdit(messageGroupBox);
m_commitMessageTextEdit->setLineWrapMode(QTextEdit::FixedColumnWidth);
m_commitMessageTextEdit->setLineWrapColumnOrWidth(72);
messageVBox->addWidget(m_commitMessageTextEdit);
setOkButtonState();
connect(m_commitMessageTextEdit, SIGNAL(textChanged()), this, SLOT(setOkButtonState()));
QHBoxLayout* messageHBox = new QHBoxLayout();
messageVBox->addLayout(messageHBox);
m_amendCheckBox = new QCheckBox(i18nc("@option:check", "Amend last commit"), messageGroupBox);
messageHBox->addWidget(m_amendCheckBox);
//read last commit message
m_alternativeMessage = GitWrapper::instance()->lastCommitMessage();
if (m_alternativeMessage.isNull()) {
m_amendCheckBox->setEnabled(false);
m_amendCheckBox->setToolTip(i18nc("@info:tooltip", "There is nothing to amend."));
} else {
connect(m_amendCheckBox, SIGNAL(stateChanged(int)),
this, SLOT(amendCheckBoxStateChanged()));
}
QPushButton * signOffButton = new QPushButton(
i18nc("@action:button Add Signed-Off line to the message widget", "Sign off"),messageGroupBox);
signOffButton->setToolTip(i18nc("@info:tooltip", "Add Signed-off-by line at the end of the commit message."));
messageHBox->addStretch();
messageHBox->addWidget(signOffButton);
//restore dialog size
FileViewGitPluginSettings* settings = FileViewGitPluginSettings::self();
this->setInitialSize(QSize(settings->commitDialogWidth(), settings->commitDialogHeight()));
connect(this, SIGNAL(finished()), this, SLOT(saveDialogSize()));
connect(signOffButton, SIGNAL(clicked(bool)), this, SLOT(signOffButtonClicked()));
}
void CommitDialog::signOffButtonClicked()
{
if (m_userName.isNull()) {
GitWrapper * gitWrapper= GitWrapper::instance();
m_userName = gitWrapper->userName();
m_userEmail = gitWrapper->userEmail();
}
//append Signed-off line
QString lastline = m_commitMessageTextEdit->document()->lastBlock().text();
bool noNewLine = lastline.startsWith(QLatin1String("Signed-off")) || lastline.isEmpty();
m_commitMessageTextEdit->append(QString(noNewLine ? "" : "\n") + "Signed-off-by: "
+ m_userName + " <" + m_userEmail + '>');
}
QByteArray CommitDialog::commitMessage() const
{
return m_localCodec->fromUnicode(m_commitMessageTextEdit->toPlainText());
}
bool CommitDialog::amend() const
{
return m_amendCheckBox->isChecked();
}
void CommitDialog::amendCheckBoxStateChanged()
{
QString tmp = m_commitMessageTextEdit->toPlainText();
m_commitMessageTextEdit->setText(m_alternativeMessage);
m_alternativeMessage = tmp;
}
void CommitDialog::saveDialogSize()
{
FileViewGitPluginSettings* settings = FileViewGitPluginSettings::self();
settings->setCommitDialogHeight(this->height());
settings->setCommitDialogWidth(this->width());
settings->writeConfig();
}
void CommitDialog::setOkButtonState()
{
bool enable = !m_commitMessageTextEdit->toPlainText().isEmpty();
this->enableButtonOk(enable);
this->setButtonToolTip(KDialog::Ok, enable ?
"" : i18nc("@info:tooltip", "You must enter a commit message first."));
}
#include "moc_commitdialog.cpp"

View file

@ -0,0 +1,65 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef COMMITDIALOG_H
#define COMMITDIALOG_H
#include <kdialog.h>
#include <QCheckBox>
#include <QTextCodec>
class KTextEdit;
class CommitDialog : public KDialog
{
Q_OBJECT
public:
CommitDialog(QWidget* parent = 0);
/**
* Returns the commit message given by the user.
* @returns The commit message.
*/
QByteArray commitMessage() const;
/**
* Indicated whether the user wants to amend the last commit.
* @returns True if the last commit is to be amended, false otherwise
*/
bool amend() const;
private slots:
void signOffButtonClicked();
void amendCheckBoxStateChanged();
void saveDialogSize();
void setOkButtonState();
private:
KTextEdit* m_commitMessageTextEdit;
QCheckBox* m_amendCheckBox;
/**
* @brief Holds an alternative message, that is not displayed currently.
* One message is the amend message, the other one for normal commits.
*/
QString m_alternativeMessage;
QTextCodec* m_localCodec;
///Cache for GitWrapper::userName();
QString m_userName;
///Cache for GitWrapper::userEmail();
QString m_userEmail;
};
#endif // COMMITDIALOG_H

View file

@ -0,0 +1,629 @@
/******************************************************************************
* Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* Copyright (C) 2010 by Johannes Steffen <jsteffen@st.ovgu.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "fileviewgitplugin.h"
#include "checkoutdialog.h"
#include "commitdialog.h"
#include "tagdialog.h"
#include "pushdialog.h"
#include "gitwrapper.h"
#include "pulldialog.h"
#include <kaction.h>
#include <kfileitem.h>
#include <kicon.h>
#include <klocale.h>
#include <ktemporaryfile.h>
#include <kurl.h>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QTextCodec>
K_PLUGIN_FACTORY(FileViewGitPluginFactory, registerPlugin<FileViewGitPlugin>();)
K_EXPORT_PLUGIN(FileViewGitPluginFactory("fileviewgitplugin"))
FileViewGitPlugin::FileViewGitPlugin(QObject* parent, const QList<QVariant>& args) :
KVersionControlPlugin(parent),
m_pendingOperation(false),
m_addAction(0),
m_removeAction(0),
m_checkoutAction(0),
m_commitAction(0),
m_tagAction(0),
m_pushAction(0),
m_pullAction(0)
{
Q_UNUSED(args);
m_addAction = new KAction(this);
m_addAction->setIcon(KIcon("list-add"));
m_addAction->setText(i18nc("@action:inmenu", "<application>Git</application> Add"));
connect(m_addAction, SIGNAL(triggered()),
this, SLOT(addFiles()));
m_removeAction = new KAction(this);
m_removeAction->setIcon(KIcon("list-remove"));
m_removeAction->setText(i18nc("@action:inmenu", "<application>Git</application> Remove"));
connect(m_removeAction, SIGNAL(triggered()),
this, SLOT(removeFiles()));
m_checkoutAction = new KAction(this);
m_checkoutAction->setIcon(KIcon("debug-step-into"));
m_checkoutAction->setText(i18nc("@action:inmenu", "<application>Git</application> Checkout..."));
connect(m_checkoutAction, SIGNAL(triggered()),
this, SLOT(checkout()));
m_commitAction = new KAction(this);
m_commitAction->setIcon(KIcon("svn-commit"));
m_commitAction->setText(i18nc("@action:inmenu", "<application>Git</application> Commit..."));
connect(m_commitAction, SIGNAL(triggered()),
this, SLOT(commit()));
m_tagAction = new KAction(this);
m_tagAction->setIcon(KIcon("bookmark-new"));
m_tagAction->setText(i18nc("@action:inmenu", "<application>Git</application> Create Tag..."));
connect(m_tagAction, SIGNAL(triggered()),
this, SLOT(createTag()));
m_pushAction = new KAction(this);
m_pushAction->setIcon(KIcon("go-top"));
m_pushAction->setText(i18nc("@action:inmenu", "<application>Git</application> Push..."));
connect(m_pushAction, SIGNAL(triggered()),
this, SLOT(push()));
m_pullAction = new KAction(this);
m_pullAction->setIcon(KIcon("go-bottom"));
m_pullAction->setText(i18nc("@action:inmenu", "<application>Git</application> Pull..."));
connect(m_pullAction, SIGNAL(triggered()),
this, SLOT(pull()));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotOperationError()));
}
FileViewGitPlugin::~FileViewGitPlugin()
{
GitWrapper::freeInstance();
}
QString FileViewGitPlugin::fileName() const
{
return QLatin1String(".git");
}
int FileViewGitPlugin::readUntilZeroChar(QIODevice* device, char* buffer, const int maxChars) {
if (buffer == 0) { // discard until next \0
char c;
while (device->getChar(&c) && c != '\0')
;
return 0;
}
int index = -1;
while (++index < maxChars) {
if (!device->getChar(&buffer[index])) {
buffer[index] = '\0';
return index == 0 ? 0 : index + 1;
}
if (buffer[index] == '\0') { // line end or we put it there (see above)
return index + 1;
}
}
return maxChars;
}
bool FileViewGitPlugin::beginRetrieval(const QString& directory)
{
Q_ASSERT(directory.endsWith('/'));
GitWrapper::instance()->setWorkingDirectory(directory);
m_currentDir = directory;
// ----- find path below git base dir -----
QProcess process;
process.setWorkingDirectory(directory);
process.start(QLatin1String("git rev-parse --show-prefix"));
QString dirBelowBaseDir = "";
while (process.waitForReadyRead()) {
char buffer[512];
while (process.readLine(buffer, sizeof(buffer)) > 0) {
dirBelowBaseDir = QString(buffer).trimmed(); // ends in "/" or is empty
}
}
m_versionInfoHash.clear();
// ----- find files with special status -----
process.start(QLatin1String("git status --porcelain -z --ignored"));
while (process.waitForReadyRead()) {
char buffer[1024];
while (readUntilZeroChar(&process, buffer, sizeof(buffer)) > 0 ) {
QString line = QTextCodec::codecForLocale()->toUnicode(buffer);
// ----- recognize file status -----
char X = line[0].toAscii(); // X and Y from the table in `man git-status`
char Y = line[1].toAscii();
const QString fileName= line.mid(3);
ItemVersion state = NormalVersion;
switch (X) {
case '!':
state = IgnoredVersion;
break;
case '?':
state = UnversionedVersion;
break;
case 'C': // handle copied as added version
case 'A':
state = AddedVersion;
break;
case 'D':
state = RemovedVersion;
break;
case 'M':
state = LocallyModifiedVersion;
break;
case 'R':
state = LocallyModifiedVersion;
// Renames list the old file name directly afterwards, separated by \0.
readUntilZeroChar(&process, 0, 0); // discard old file name
break;
}
// overwrite status depending on the working tree
switch (Y) {
case 'D': // handle "deleted in working tree" as "modified in working tree"
case 'M':
state = LocallyModifiedUnstagedVersion;
break;
}
// overwrite status in case of conflicts (lower part of the table in `man git-status`)
if (X == 'U' ||
Y == 'U' ||
(X == 'A' && Y == 'A') ||
(X == 'D' && Y == 'D')) {
state = ConflictingVersion;
}
// ----- decide what to record about that file -----
if (state == NormalVersion || !fileName.startsWith(dirBelowBaseDir)) {
continue;
}
/// File name relative to the current working directory.
const QString relativeFileName = fileName.mid(dirBelowBaseDir.length());
//if file is part of a sub-directory, record the directory
if (relativeFileName.contains('/')) {
if (state == IgnoredVersion)
continue;
if (state == AddedVersion || state == RemovedVersion) {
state = LocallyModifiedVersion;
}
const QString absoluteDirName = directory + relativeFileName.left(relativeFileName.indexOf('/'));
if (m_versionInfoHash.contains(absoluteDirName)) {
ItemVersion oldState = m_versionInfoHash.value(absoluteDirName);
//only keep the most important state for a directory
if (oldState == ConflictingVersion)
continue;
if (oldState == LocallyModifiedUnstagedVersion && state != ConflictingVersion)
continue;
if (oldState == LocallyModifiedVersion &&
state != LocallyModifiedUnstagedVersion && state != ConflictingVersion)
continue;
m_versionInfoHash.insert(absoluteDirName, state);
} else {
m_versionInfoHash.insert(absoluteDirName, state);
}
} else { //normal file, no directory
m_versionInfoHash.insert(directory + relativeFileName, state);
}
}
}
return true;
}
void FileViewGitPlugin::endRetrieval()
{
}
KVersionControlPlugin::ItemVersion FileViewGitPlugin::itemVersion(const KFileItem& item) const
{
const QString itemUrl = item.localPath();
if (m_versionInfoHash.contains(itemUrl)) {
return m_versionInfoHash.value(itemUrl);
} else {
// files that are not in our map are normal, tracked files by definition
return NormalVersion;
}
}
QList<QAction*> FileViewGitPlugin::actions(const KFileItemList &items) const
{
if (items.count() == 1 && items.first().isDir() &&
items.first().url().path(KUrl::AddTrailingSlash) == m_currentDir) {
return contextMenuDirectoryActions(items.first().url().path(KUrl::AddTrailingSlash));
} else {
return contextMenuFilesActions(items);
}
}
QList<QAction*> FileViewGitPlugin::contextMenuFilesActions(const KFileItemList& items) const
{
Q_ASSERT(!items.isEmpty());
if (!m_pendingOperation){
m_contextDir.clear();
m_contextItems.clear();
foreach(const KFileItem& item, items){
m_contextItems.append(item);
}
//see which actions should be enabled
int versionedCount = 0;
int addableCount = 0;
foreach(const KFileItem& item, items){
const ItemVersion state = itemVersion(item);
if (state != UnversionedVersion && state != RemovedVersion &&
state != IgnoredVersion) {
++versionedCount;
}
if (state == UnversionedVersion || state == LocallyModifiedUnstagedVersion ||
state == IgnoredVersion) {
++addableCount;
}
}
m_addAction->setEnabled(addableCount == items.count());
m_removeAction->setEnabled(versionedCount == items.count());
}
else{
m_addAction->setEnabled(false);
m_removeAction->setEnabled(false);
}
QList<QAction*> actions;
actions.append(m_addAction);
actions.append(m_removeAction);
return actions;
}
QList<QAction*> FileViewGitPlugin::contextMenuDirectoryActions(const QString& directory) const
{
QList<QAction*> actions;
if (!m_pendingOperation){
m_contextDir = directory;
}
m_checkoutAction->setEnabled(!m_pendingOperation);
actions.append(m_checkoutAction);
bool canCommit = false;
QHash<QString, ItemVersion>::const_iterator it = m_versionInfoHash.constBegin();
while (it != m_versionInfoHash.constEnd()) {
const ItemVersion state = it.value();
if (state == LocallyModifiedVersion || state == AddedVersion || state == RemovedVersion) {
canCommit = true;
}
if (state == ConflictingVersion) {
canCommit = false;
break;
}
++it;
}
m_commitAction->setEnabled(!m_pendingOperation && canCommit);
actions.append(m_commitAction);
m_tagAction->setEnabled(!m_pendingOperation);
actions.append(m_tagAction);
m_pushAction->setEnabled(!m_pendingOperation);
actions.append(m_pushAction);
m_pullAction->setEnabled(!m_pendingOperation);
actions.append(m_pullAction);
return actions;
}
void FileViewGitPlugin::addFiles()
{
execGitCommand(QLatin1String("add"), QStringList(),
i18nc("@info:status", "Adding files to <application>Git</application> repository..."),
i18nc("@info:status", "Adding files to <application>Git</application> repository failed."),
i18nc("@info:status", "Added files to <application>Git</application> repository."));
}
void FileViewGitPlugin::removeFiles()
{
QStringList arguments;
arguments << "-r"; //recurse through directories
arguments << "--force"; //also remove files that have not been committed yet
execGitCommand(QLatin1String("rm"), arguments,
i18nc("@info:status", "Removing files from <application>Git</application> repository..."),
i18nc("@info:status", "Removing files from <application>Git</application> repository failed."),
i18nc("@info:status", "Removed files from <application>Git</application> repository."));
}
void FileViewGitPlugin::checkout()
{
CheckoutDialog dialog;
if (dialog.exec() == QDialog::Accepted){
QProcess process;
process.setWorkingDirectory(m_contextDir);
QStringList arguments;
arguments << "checkout";
if (dialog.force()) {
arguments << "-f";
}
const QString newBranchName = dialog.newBranchName();
if (!newBranchName.isEmpty()) {
arguments << "-b";
arguments << newBranchName;
}
const QString checkoutIdentifier = dialog.checkoutIdentifier();
if (!checkoutIdentifier.isEmpty()) {
arguments << checkoutIdentifier;
}
//to appear in messages
const QString currentBranchName = newBranchName.isEmpty() ? checkoutIdentifier : newBranchName;
process.start(QLatin1String("git"), arguments);
process.setReadChannel(QProcess::StandardError); //git writes info messages to stderr as well
QString completedMessage;
while (process.waitForReadyRead()) {
char buffer[512];
while (process.readLine(buffer, sizeof(buffer)) > 0){
const QString currentLine(buffer);
if (currentLine.startsWith(QLatin1String("Switched to branch"))) {
completedMessage = i18nc("@info:status", "Switched to branch '%1'", currentBranchName);
}
if (currentLine.startsWith(QLatin1String("HEAD is now at"))) {
const QString headIdentifier = currentLine.
mid(QString("HEAD is now at ").length()).trimmed();
completedMessage = i18nc("@info:status Git HEAD pointer, parameter includes "
"short SHA-1 & commit message ", "HEAD is now at %1", headIdentifier);
}
//special output for checkout -b
if (currentLine.startsWith(QLatin1String("Switched to a new branch"))) {
completedMessage = i18nc("@info:status", "Switched to a new branch '%1'", currentBranchName);
}
}
}
if (process.exitCode() == 0 && process.exitStatus() == QProcess::NormalExit) {
if (!completedMessage.isEmpty()) {
emit operationCompletedMessage(completedMessage);
emit itemVersionsChanged();
}
}
else {
emit errorMessage(i18nc("@info:status", "<application>Git</application> Checkout failed."
" Maybe your working directory is dirty."));
}
}
}
void FileViewGitPlugin::commit()
{
CommitDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
KTemporaryFile tmpCommitMessageFile;
tmpCommitMessageFile.open();
tmpCommitMessageFile.write(dialog.commitMessage());
tmpCommitMessageFile.close();
QProcess process;
process.setWorkingDirectory(m_contextDir);
process.start(QString("git commit") + (dialog.amend() ? " --amend" : "")+ " -F " + tmpCommitMessageFile.fileName());
QString completedMessage;
while (process.waitForReadyRead()){
char buffer[512];
while (process.readLine(buffer, sizeof(buffer)) > 0) {
if (strlen(buffer) > 0 && buffer[0] == '[') {
completedMessage = QTextCodec::codecForLocale()->toUnicode(buffer).trimmed();
break;
}
}
}
if (!completedMessage.isEmpty()) {
emit operationCompletedMessage(completedMessage);
emit itemVersionsChanged();
}
}
}
void FileViewGitPlugin::createTag()
{
TagDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
KTemporaryFile tempTagMessageFile;
tempTagMessageFile.open();
tempTagMessageFile.write(dialog.tagMessage());
tempTagMessageFile.close();
QProcess process;
process.setWorkingDirectory(m_contextDir);
process.setReadChannel(QProcess::StandardError);
process.start(QString("git tag -a -F %1 %2 %3").arg(tempTagMessageFile.fileName()).
arg(dialog.tagName()).arg(dialog.baseBranch()));
QString completedMessage;
bool gotTagAlreadyExistsMessage = false;
while (process.waitForReadyRead()) {
char buffer[512];
while (process.readLine(buffer, sizeof(buffer)) > 0) {
QString line(buffer);
if (line.contains("already exists")) {
gotTagAlreadyExistsMessage = true;
}
}
}
if (process.exitCode() == 0 && process.exitStatus() == QProcess::NormalExit) {
completedMessage = i18nc("@info:status","Successfully created tag '%1'", dialog.tagName());
emit operationCompletedMessage(completedMessage);
} else {
//I don't know any other error, but in case one occurs, the user doesn't get FALSE error messages
emit errorMessage(gotTagAlreadyExistsMessage ?
i18nc("@info:status", "<application>Git</application> tag creation failed."
" A tag with the name '%1' already exists.", dialog.tagName()) :
i18nc("@info:status", "<application>Git</application> tag creation failed.")
);
}
}
}
void FileViewGitPlugin::push()
{
PushDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
m_process.setWorkingDirectory(m_contextDir);
m_errorMsg = i18nc("@info:status", "Pushing branch %1 to %2:%3 failed.",
dialog.localBranch(), dialog.destination(), dialog.remoteBranch());
m_operationCompletedMsg = i18nc("@info:status", "Pushed branch %1 to %2:%3.",
dialog.localBranch(), dialog.destination(), dialog.remoteBranch());
emit infoMessage(i18nc("@info:status", "Pushing branch %1 to %2:%3...",
dialog.localBranch(), dialog.destination(), dialog.remoteBranch()));
m_command = "push";
m_pendingOperation = true;
m_process.start(QString("git push%4 %1 %2:%3").arg(dialog.destination()).
arg(dialog.localBranch()).arg(dialog.remoteBranch()).
arg(dialog.force() ? QLatin1String(" --force") : QLatin1String("")));
}
}
void FileViewGitPlugin::pull()
{
PullDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
m_process.setWorkingDirectory(m_contextDir);
m_errorMsg = i18nc("@info:status", "Pulling branch %1 from %2 failed.",
dialog.remoteBranch(), dialog.source());
m_operationCompletedMsg = i18nc("@info:status", "Pulled branch %1 from %2 successfully.",
dialog.remoteBranch(), dialog.source());
emit infoMessage(i18nc("@info:status", "Pulling branch %1 from %2...", dialog.remoteBranch(),
dialog.source()));
m_command = "pull";
m_pendingOperation = true;
m_process.start(QString("git pull %1 %2").arg(dialog.source()).arg(dialog.remoteBranch()));
}
}
void FileViewGitPlugin::slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus)
{
m_pendingOperation = false;
QString message;
if (m_command == QLatin1String("push")) { //output parsing for push
message = parsePushOutput();
m_command = "";
}
if (m_command == QLatin1String("pull")) {
message = parsePullOutput();
m_command = "";
}
if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
emit errorMessage(message.isNull() ? m_errorMsg : message);
} else if (m_contextItems.isEmpty()) {
emit operationCompletedMessage(message.isNull() ? m_operationCompletedMsg : message);
emit itemVersionsChanged();
} else {
startGitCommandProcess();
}
}
void FileViewGitPlugin::slotOperationError()
{
// don't do any operation on other items anymore
m_contextItems.clear();
m_pendingOperation = false;
emit errorMessage(m_errorMsg);
}
QString FileViewGitPlugin::parsePushOutput()
{
m_process.setReadChannel(QProcess::StandardError);
QString message;
char buffer[256];
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
const QString line(buffer);
if (line.contains("->") || (line.contains("fatal") && message.isNull())) {
message = line.trimmed();
}
if (line.contains("Everything up-to-date") && message.isNull()) {
message = i18nc("@info:status", "Branch is already up-to-date.");
}
}
return message;
}
QString FileViewGitPlugin::parsePullOutput()
{
char buffer[256];
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
const QString line(buffer);
if (line.contains("Already up-to-date")) {
return i18nc("@info:status", "Branch is already up-to-date.");
}
if (line.contains("CONFLICT")) {
emit itemVersionsChanged();
return i18nc("@info:status", "Merge conflicts occurred. Fix them and commit the result.");
}
}
return QString();
}
void FileViewGitPlugin::execGitCommand(const QString& gitCommand,
const QStringList& arguments,
const QString& infoMsg,
const QString& errorMsg,
const QString& operationCompletedMsg)
{
emit infoMessage(infoMsg);
m_command = gitCommand;
m_arguments = arguments;
m_errorMsg = errorMsg;
m_operationCompletedMsg = operationCompletedMsg;
startGitCommandProcess();
}
void FileViewGitPlugin::startGitCommandProcess()
{
Q_ASSERT(!m_contextItems.isEmpty());
Q_ASSERT(m_process.state() == QProcess::NotRunning);
m_pendingOperation = true;
const KFileItem item = m_contextItems.takeLast();
m_process.setWorkingDirectory(item.url().directory());
QStringList arguments;
arguments << m_command;
arguments << m_arguments;
//force explicitly selected files but no files in selected directories
if (m_command == "add" && !item.isDir()){
arguments<< QLatin1String("-f");
}
arguments << item.url().fileName();
m_process.start(QLatin1String("git"), arguments);
// the remaining items of m_contextItems will be executed
// after the process has finished (see slotOperationFinished())
}
#include "moc_fileviewgitplugin.cpp"

View file

@ -0,0 +1,52 @@
[Desktop Entry]
Type=Service
Name=Git
Name[ar]=Git
Name[ast]=Git
Name[bg]=Git
Name[bs]=Git
Name[ca]=Git
Name[ca@valencia]=Git
Name[cs]=Git
Name[da]=Git
Name[de]=Git
Name[el]=Git
Name[en_GB]=Git
Name[es]=Git
Name[et]=Git
Name[fi]=Git
Name[fr]=Git
Name[ga]=Git
Name[gl]=Git
Name[hu]=Git
Name[it]=Git
Name[kk]=Git
Name[km]=Git
Name[ko]=Git
Name[lt]=Git
Name[mr]=ि
Name[nb]=Git
Name[nds]=Git
Name[nl]=Git
Name[pa]=Git
Name[pl]=Git
Name[pt]=Git
Name[pt_BR]=Git
Name[ro]=Git
Name[ru]=Git
Name[sk]=Git
Name[sl]=Git
Name[sr]=Гит
Name[sr@ijekavian]=Гит
Name[sr@ijekavianlatin]=Git
Name[sr@latin]=Git
Name[sv]=Git
Name[tr]=Git
Name[ug]=Git
Name[uk]=Git
Name[x-test]=xxGitxx
Name[zh_CN]=Git
Name[zh_TW]=Git
X-KDE-ServiceTypes=FileViewVersionControlPlugin
MimeType=text/plain;
X-KDE-Library=fileviewgitplugin

View file

@ -0,0 +1,122 @@
/******************************************************************************
* Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef FILEVIEWGITPLUGIN_H
#define FILEVIEWGITPLUGIN_H
#include <kfileitem.h>
#include <kversioncontrolplugin.h>
#include <QList>
#include <QHash>
#include <QProcess>
#include <QString>
/**
* @brief Git implementation for the KVersionControlPlugin interface.
*/
class FileViewGitPlugin : public KVersionControlPlugin
{
Q_OBJECT
public:
FileViewGitPlugin(QObject* parent, const QList<QVariant>& args);
virtual ~FileViewGitPlugin();
virtual QString fileName() const;
virtual bool beginRetrieval(const QString& directory);
virtual void endRetrieval();
virtual KVersionControlPlugin::ItemVersion itemVersion(const KFileItem& item) const;
virtual QList<QAction*> actions(const KFileItemList &items) const;
private slots:
void addFiles();
void removeFiles();
void checkout();
void commit();
void createTag();
void push();
void pull();
void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
void slotOperationError();
private:
QList<QAction*> contextMenuFilesActions(const KFileItemList& items) const;
QList<QAction*> contextMenuDirectoryActions(const QString& directory) const;
/**
* Reads into buffer from device until we reach the next \0 or maxChars have been read.
* @returns The number of characters read.
*/
int readUntilZeroChar(QIODevice* device, char* buffer, const int maxChars);
/**
* Parses the output of the git push command and returns an appropriate message,
* that should be displayed to the user.
* @returns The error or success message to be printed to the user
*/
QString parsePushOutput();
/**
* Parses the output of the git pull command and returns an appropriate message,
* that should be displayed to the user.
* @returns The error or success message to be printed to the user
*/
QString parsePullOutput();
/**
* Executes the command "git {svnCommand}" for the files that have been
* set by getting the context menu actions (see contextMenuActions()).
* @param infoMsg Message that should be shown before the command is executed.
* @param errorMsg Message that should be shown if the execution of the command
* has failed.
* @param operationCompletedMsg
* Message that should be shown if the execution of the command
* has been completed successfully.
*/
void execGitCommand(const QString& gitCommand,
const QStringList& arguments,
const QString& infoMsg,
const QString& errorMsg,
const QString& operationCompletedMsg);
void startGitCommandProcess();
private:
bool m_pendingOperation;
/**
* Contains all files in the current directory, whose version state is not
* NormalVersion and directories containing such files (except for directories
* whose only special contained file type is IgnoredVersion).
*/
QHash<QString, ItemVersion> m_versionInfoHash;
QAction* m_addAction;
QAction* m_removeAction;
QAction* m_checkoutAction;
QAction* m_commitAction;
QAction* m_tagAction;
QAction* m_pushAction;
QAction* m_pullAction;
QString m_currentDir;
QProcess m_process;
QString m_command;
QStringList m_arguments;
QString m_operationCompletedMsg;
QString m_errorMsg;
//Current targets. m_contextItems is used if and only if m_contextDir is empty.
mutable QString m_contextDir;
mutable KFileItemList m_contextItems;
};
#endif // FILEVIEWGITPLUGIN_H

View file

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0">
<kcfgfile name="fileviewgitpluginrc"/>
<group name="CommitDialogSettings">
<entry name="commitDialogHeight" type="Int">
<label>Dialog height</label>
<default>300</default>
<min>50</min>
</entry>
<entry name="commitDialogWidth" type="Int">
<label>Dialog width</label>
<default>500</default>
<min>50</min>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,5 @@
File=fileviewgitpluginsettings.kcfg
ClassName=FileViewGitPluginSettings
Singleton=true
Mutators=true

View file

@ -0,0 +1,171 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "gitwrapper.h"
#include <QTextCodec>
GitWrapper* GitWrapper::m_instance = 0;
const int GitWrapper::BUFFER_SIZE = 256;
const int GitWrapper::SMALL_BUFFER_SIZE = 128;
GitWrapper::GitWrapper()
{
m_localCodec = QTextCodec::codecForLocale();
}
GitWrapper* GitWrapper::instance()
{
if (m_instance == 0) {
m_instance = new GitWrapper();
}
return m_instance;
}
void GitWrapper::freeInstance()
{
delete m_instance;
m_instance = 0;
}
QString GitWrapper::userName()
{
QString result("");
char buffer[SMALL_BUFFER_SIZE];
m_process.start("git config --get user.name");
while (m_process.waitForReadyRead()) {
if (m_process.readLine(buffer, sizeof(buffer)) > 0) {
result = m_localCodec->toUnicode(buffer).trimmed();
}
}
return result;
}
QString GitWrapper::userEmail()
{
QString result("");
char buffer[SMALL_BUFFER_SIZE];
m_process.start("git config --get user.email");
while (m_process.waitForReadyRead()) {
if (m_process.readLine(buffer, sizeof(buffer)) > 0) {
result = m_localCodec->toUnicode(buffer).trimmed();
}
}
return result;
}
QStringList GitWrapper::branches(int* currentBranchIndex)
{
QStringList result;
if (currentBranchIndex != 0) {
*currentBranchIndex = -1;
}
m_process.start(QLatin1String("git branch -a"));
while (m_process.waitForReadyRead()) {
char buffer[BUFFER_SIZE];
while (m_process.readLine(buffer, sizeof(buffer)) > 0){
const QString branchName = m_localCodec->toUnicode(buffer).mid(2).trimmed();
//don't list non-branches and HEAD-branches directly pointing to other branches
if (!branchName.contains("->") && !branchName.startsWith('(')) {
result.append(branchName);
if (currentBranchIndex !=0 && buffer[0]=='*') {
*currentBranchIndex = result.size() - 1;
}
}
}
}
return result;
}
void GitWrapper::tagSet(QSet<QString>& result)
{
m_process.start(QLatin1String("git tag"));
while (m_process.waitForReadyRead()) {
char buffer[BUFFER_SIZE];
while (m_process.readLine(buffer, sizeof(buffer)) > 0){
const QString tagName = m_localCodec->toUnicode(buffer).trimmed();
result.insert(tagName);
}
}
}
QStringList GitWrapper::tags()
{
QStringList result;
m_process.start(QLatin1String("git tag"));
while (m_process.waitForReadyRead()) {
char buffer[BUFFER_SIZE];
while (m_process.readLine(buffer, sizeof(buffer)) > 0){
const QString tagName = m_localCodec->toUnicode(buffer).trimmed();
result.append(tagName);
}
}
return result;
}
inline QStringList GitWrapper::remotes(QLatin1String lineEnd)
{
QStringList result;
m_process.start(QLatin1String("git remote -v"));
while (m_process.waitForReadyRead()) {
char buffer[BUFFER_SIZE];
while (m_process.readLine(buffer, sizeof(buffer)) > 0){
const QString line = QString(buffer).simplified();
if (line.endsWith(lineEnd)) {
result.append(line.section(' ', 0, 0));
}
}
}
return result;
}
QStringList GitWrapper::pullRemotes()
{
return remotes(QLatin1String("(fetch)"));
}
QStringList GitWrapper::pushRemotes()
{
return remotes(QLatin1String("(push)"));
}
QString GitWrapper::lastCommitMessage()
{
QString result;
char buffer[BUFFER_SIZE];
m_process.start("git log -1");
while (m_process.waitForReadyRead()) {
bool inMessage = false;
QStringList message;
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
const QString currentLine(buffer);
if (inMessage){
message << m_localCodec->toUnicode(buffer).trimmed();
}
else if (currentLine.startsWith(QLatin1String("Date:"))) {
m_process.readLine();
inMessage = true;
}
}
result = message.join("\n");
}
return result;
}

View file

@ -0,0 +1,105 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef GITWRAPPER_H
#define GITWRAPPER_H
#include <QProcess>
#include <QStringList>
#include <QSet>
#include <QTextCodec>
/**
* @brief A git wrapper class to access git functions conveniently using a Singleton interface.
*/
class GitWrapper
{
private:
GitWrapper();
static GitWrapper* m_instance;
///size of the line buffers when parsing git output
static const int BUFFER_SIZE;
///size of the line buffers when parsing shorter git output
static const int SMALL_BUFFER_SIZE;
QProcess m_process;
QTextCodec * m_localCodec;
/**
* Gets a list of all remote hosts, whose entry ends with \a lineEnd
* @param lineEnd The end of the lines, which should be returned as entries.
* Should be "(pull)" or "(push)".
*/
QStringList remotes(QLatin1String lineEnd);
public:
static GitWrapper* instance();
static void freeInstance();
void setWorkingDirectory(const QString& workingDirectory) {
m_process.setWorkingDirectory(workingDirectory);
}
/**
* @returns The configured user.name of the repository,
the empty String (which is NOT null) if not configured.
*/
QString userName();
/**
* @returns The configured user.email of the repository,
the empty String (which is NOT null) if not configured.
*/
QString userEmail();
/**
* Gets a list of all branches in the repository.
* @param currentBranchIndex
* Pointer to the location in which to store the index of the current branch
* within the returned QStringList. Set to -1 if currently not on any branch.
* @returns A StringList containing the names of all local and remote branches.
*/
QStringList branches(int * currentBranchIndex = 0);
/**
* Gets a list of all tags in the repository.
* @returns A list containing the tag names
*/
QStringList tags();
/**
* Gets a set of all tags in the repository.
* @param result Set to store the results in.
*/
void tagSet(QSet<QString>& result);
/**
* Gets a list of all remote hosts we can pull from.
* @returns The list containing the remote hosts.
*/
QStringList pullRemotes();
/**
* Gets a list of all remote hosts we can push to.
* @returns The list containing the remote hosts.
*/
QStringList pushRemotes();
/**
* @returns The last commit message. Null-String if there is no last commit.
*/
QString lastCommitMessage();
};
#endif // GITWRAPPER_H

View file

@ -0,0 +1,102 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "pulldialog.h"
#include "gitwrapper.h"
#include <kcombobox.h>
#include <klocale.h>
#include <kvbox.h>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
PullDialog::PullDialog(QWidget* parent):
KDialog(parent, Qt::Dialog)
{
this->setCaption(i18nc("@title:window", "<application>Git</application> Pull"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Pull"));
KVBox * vbox = new KVBox(this);
this->setMainWidget(vbox);
QGroupBox * sourceGroupBox = new QGroupBox(vbox);
sourceGroupBox->setTitle(i18nc("@title:group The source to pull from", "Source"));
QHBoxLayout * sourceHBox = new QHBoxLayout(sourceGroupBox);
sourceGroupBox->setLayout(sourceHBox);
QLabel * remoteLabel = new QLabel(i18nc("@label:listbox a git remote", "Remote:"), sourceGroupBox);
sourceHBox->addWidget(remoteLabel);
m_remoteComboBox = new KComboBox(false, sourceGroupBox);
sourceHBox->addWidget(m_remoteComboBox);
QLabel * remoteBranchLabel = new QLabel(i18nc("@label:listbox", "Remote branch:"), sourceGroupBox);
sourceHBox->addWidget(remoteBranchLabel);
m_remoteBranchComboBox = new KComboBox(false, sourceGroupBox);
sourceHBox->addWidget(m_remoteBranchComboBox);
//populate UI
GitWrapper * gitWrapper = GitWrapper::instance();
//get sources
m_remoteComboBox->addItems(gitWrapper->pullRemotes());
//get branch names
int currentBranchIndex;
QStringList branches = gitWrapper->branches(&currentBranchIndex);
for (int i=0; i < branches.size(); ++i) {
if (branches[i].startsWith(QLatin1String("remotes/")) &&
branches[i].count(QChar('/')) > 1) {
const QStringList sections = branches[i].split('/');
QHash<QString,QStringList>::iterator entry = m_remoteBranches.find(sections.at(1));
if (entry == m_remoteBranches.end()) {
m_remoteBranches.insert(sections.at(1), QStringList() << sections.at(2));
} else {
entry.value().append(sections.at(2));
}
}
}
remoteSelectionChanged(m_remoteComboBox->currentText());
//Signals
connect(m_remoteComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(remoteSelectionChanged(QString)));
}
QString PullDialog::source() const
{
return m_remoteComboBox->currentText();
}
QString PullDialog::remoteBranch() const
{
return m_remoteBranchComboBox->currentText();
}
void PullDialog::remoteSelectionChanged(const QString& newRemote)
{
m_remoteBranchComboBox->clear();
m_remoteBranchComboBox->addItems(m_remoteBranches.value(newRemote));
this->enableButtonOk(m_remoteBranchComboBox->count() > 0);
}
#include "moc_pulldialog.cpp"

View file

@ -0,0 +1,42 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef PULLDIALOG_H
#define PULLDIALOG_H
#include <kdialog.h>
class KComboBox;
class PullDialog : public KDialog
{
Q_OBJECT
public:
PullDialog(QWidget* parent = 0);
QString source() const;
QString remoteBranch() const;
private:
KComboBox * m_remoteComboBox;
KComboBox * m_remoteBranchComboBox;
QHash<QString, QStringList> m_remoteBranches;
private slots:
void remoteSelectionChanged(const QString& newRemote);
};
#endif // PULLDIALOG_H

View file

@ -0,0 +1,155 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "pushdialog.h"
#include "gitwrapper.h"
#include <kcombobox.h>
#include <klocale.h>
#include <kvbox.h>
#include <QCheckBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
PushDialog::PushDialog (QWidget* parent ):
KDialog (parent, Qt::Dialog)
{
this->setCaption(i18nc("@title:window", "<application>Git</application> Push"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Push"));
KVBox * vbox = new KVBox(this);
this->setMainWidget(vbox);
//Destination
QGroupBox * destinationGroupBox = new QGroupBox(vbox);
destinationGroupBox->setTitle(i18nc("@title:group The remote host", "Destination"));
QHBoxLayout * destinationHBox = new QHBoxLayout(destinationGroupBox);
destinationGroupBox->setLayout(destinationHBox);
QLabel * remoteLabel = new QLabel(i18nc("@label:listbox a git remote", "Remote:"), destinationGroupBox);
destinationHBox->addWidget(remoteLabel);
m_remoteComboBox = new KComboBox(false, destinationGroupBox);
destinationHBox->addWidget(m_remoteComboBox);
destinationHBox->addStretch();
//Branches
QGroupBox* branchesGroupBox = new QGroupBox(vbox);
branchesGroupBox->setTitle(i18nc("@title:group", "Branches"));
QHBoxLayout * branchesHBox = new QHBoxLayout(branchesGroupBox);
branchesGroupBox->setLayout(branchesHBox);
QLabel * localBranchLabel = new QLabel(i18nc("@label:listbox", "Local Branch:"), branchesGroupBox);
branchesHBox->addWidget(localBranchLabel);
m_localBranchComboBox = new KComboBox(false, branchesGroupBox);
branchesHBox->addWidget(m_localBranchComboBox);
branchesHBox->addStretch();
QLabel * remoteBranchLabel = new QLabel(i18nc("@label:listbox", "Remote Branch:"), branchesGroupBox);
branchesHBox->addWidget(remoteBranchLabel);
m_remoteBranchComboBox = new KComboBox(false, branchesGroupBox);
branchesHBox->addWidget(m_remoteBranchComboBox);
QGroupBox* optionsGroupBox = new QGroupBox(vbox);
optionsGroupBox->setTitle(i18nc("@title:group", "Options"));
QHBoxLayout * optionsHBox = new QHBoxLayout(optionsGroupBox);
optionsGroupBox->setLayout(optionsHBox);
m_forceCheckBox = new QCheckBox(i18nc("@option:check", "Force"), optionsGroupBox);
m_forceCheckBox->setToolTip(i18nc("@info:tooltip", "Proceed even if the remote branch is not an ancestor of the local branch."));
optionsHBox->addWidget(m_forceCheckBox);
//populate UI
GitWrapper * gitWrapper = GitWrapper::instance();
//get destinations
QStringList remotes = gitWrapper->pushRemotes();
m_remoteComboBox->addItems(remotes);
//get branch names
int currentBranchIndex;
QStringList branches = gitWrapper->branches(&currentBranchIndex);
for (int i=0; i < branches.size(); ++i){
if (branches[i].startsWith(QLatin1String("remotes/"))) {
const QStringList sections = branches[i].split('/');
if (sections.size() > 2) {
QHash<QString,QStringList>::iterator entry = m_remoteBranches.find(sections.at(1));
if (entry == m_remoteBranches.end()) {
m_remoteBranches.insert(sections.at(1), QStringList() << sections.at(2));
} else {
entry.value().append(sections.at(2));
}
}
} else {
m_localBranchComboBox->addItem(branches[i]);
if (i == currentBranchIndex) {
m_localBranchComboBox->setCurrentIndex(m_localBranchComboBox->count()-1);
}
}
}
remoteSelectionChanged(m_remoteComboBox->currentText());
//Signals
connect(m_remoteComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(remoteSelectionChanged(QString)));
connect(m_localBranchComboBox, SIGNAL(currentIndexChanged(QString)),
this, SLOT(localBranchSelectionChanged(QString)));
}
QString PushDialog::destination() const
{
return m_remoteComboBox->currentText();
}
QString PushDialog::localBranch() const
{
return m_localBranchComboBox->currentText();
}
QString PushDialog::remoteBranch() const
{
return m_remoteBranchComboBox->currentText();
}
bool PushDialog::force() const
{
return m_forceCheckBox->isChecked();
}
void PushDialog::remoteSelectionChanged(const QString& newRemote)
{
m_remoteBranchComboBox->clear();
m_remoteBranchComboBox->addItems(m_remoteBranches.value(newRemote));
localBranchSelectionChanged(m_localBranchComboBox->currentText());
}
void PushDialog::localBranchSelectionChanged(const QString& newLocalBranch)
{
//select matching remote branch if possible
const int index = m_remoteBranchComboBox->findText(newLocalBranch);
if (index != -1) {
m_remoteBranchComboBox->setCurrentIndex(index);
}
this->enableButtonOk(m_remoteBranchComboBox->count() > 0);
}
#include "moc_pushdialog.cpp"

View file

@ -0,0 +1,50 @@
/******************************************************************************
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef PUSHDIALOG_H
#define PUSHDIALOG_H
#include <kdialog.h>
class KComboBox;
#include <QCheckBox>
class PushDialog : public KDialog
{
Q_OBJECT
public:
PushDialog(QWidget* parent = 0);
QString destination() const;
QString localBranch() const;
QString remoteBranch() const;
bool force() const;
private slots:
void remoteSelectionChanged(const QString& newRemote);
void localBranchSelectionChanged(const QString& newLocalBranch);
private:
QHash<QString, QStringList> m_remoteBranches;
KComboBox * m_remoteComboBox;
KComboBox * m_localBranchComboBox;
KComboBox * m_remoteBranchComboBox;
QCheckBox * m_forceCheckBox;
};
#endif // PUSHDIALOG_H

View file

@ -0,0 +1,141 @@
/******************************************************************************
* Copyright (C) 2010 by Johannes Steffen <johannes.steffen@st.ovgu.de> *
* Copyright (C) 2010 by Sebastian Doerner <sebastian@sebastian-doerner.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#include "tagdialog.h"
#include "gitwrapper.h"
#include <kcombobox.h>
#include <klineedit.h>
#include <klocale.h>
#include <ktextedit.h>
#include <kvbox.h>
#include <QCheckBox>
#include <QGroupBox>
#include <QPushButton>
#include <QTextCodec>
#include <QVBoxLayout>
#include <QLabel>
TagDialog::TagDialog (QWidget* parent ):
KDialog (parent, Qt::Dialog),
m_localCodec(QTextCodec::codecForLocale())
{
this->setCaption(i18nc("@title:window", "<application>Git</application> Create Tag"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Create Tag"));
KVBox* vbox = new KVBox(this);
this->setMainWidget(vbox);
QGroupBox* tagInformationGroupBox = new QGroupBox(vbox);
tagInformationGroupBox->setTitle(i18nc("@title:group", "Tag Information"));
QVBoxLayout * tagInformationLayout = new QVBoxLayout(tagInformationGroupBox);
tagInformationGroupBox->setLayout(tagInformationLayout);
QLabel* nameLabel = new QLabel(i18nc("@label:textbox", "Tag Name:"), tagInformationGroupBox);
tagInformationLayout->addWidget(nameLabel);
m_tagNameTextEdit = new KLineEdit(tagInformationGroupBox);
tagInformationLayout->addWidget(m_tagNameTextEdit);
setOkButtonState();
connect(m_tagNameTextEdit, SIGNAL(textChanged(QString)), this, SLOT(setOkButtonState()));
QLabel* messageLabel = new QLabel(i18nc("@label:textbox", "Tag Message:"), tagInformationGroupBox);
tagInformationLayout->addWidget(messageLabel);
m_tagMessageTextEdit = new KTextEdit(tagInformationGroupBox);
m_tagMessageTextEdit->setLineWrapMode(QTextEdit::FixedColumnWidth);
m_tagMessageTextEdit->setLineWrapColumnOrWidth(72);
tagInformationLayout->addWidget(m_tagMessageTextEdit);
QGroupBox* attachToGroupBox = new QGroupBox(vbox);
attachToGroupBox->setTitle(i18nc("@title:group", "Attach to"));
QHBoxLayout* attachToLayout = new QHBoxLayout();
attachToGroupBox->setLayout(attachToLayout);
QLabel* branchLabel = new QLabel(i18nc("@label:listbox", "Branch:"), attachToGroupBox);
attachToLayout->addWidget(branchLabel);
m_branchComboBox = new KComboBox(false, attachToGroupBox);
attachToLayout->addWidget(m_branchComboBox);
attachToLayout->addStretch();
this->setInitialSize(QSize(300,200));
//initialize alternate color scheme for errors
m_errorColors = m_tagNameTextEdit->palette();
m_errorColors.setColor(QPalette::Normal, QPalette::Base, Qt::red);
m_errorColors.setColor(QPalette::Inactive, QPalette::Base, Qt::red);
//get branch & tag names
GitWrapper * gitWrapper = GitWrapper::instance();
int currentIndex;
const QStringList branches = gitWrapper->branches(&currentIndex);
m_branchComboBox->addItems(branches);
m_branchComboBox->setCurrentIndex(currentIndex);
gitWrapper->tagSet(m_tagNames);
}
QByteArray TagDialog::tagMessage() const
{
return m_localCodec->fromUnicode(m_tagMessageTextEdit->toPlainText());
}
QString TagDialog::tagName() const
{
return m_tagNameTextEdit->text().trimmed();
}
QString TagDialog::baseBranch() const
{
return m_branchComboBox->currentText();
}
void TagDialog::setOkButtonState()
{
const QString tagName = m_tagNameTextEdit->text().trimmed();
QString toolTip;
if (tagName.isEmpty()) {
toolTip = i18nc("@info:tooltip", "You must enter a tag name first.");
}
else if (tagName.contains(QRegExp("\\s"))) {
toolTip = i18nc("@info:tooltip", "Tag names may not contain any whitespace.");
}
else if (m_tagNames.contains(tagName)) {
toolTip = i18nc("@info:tooltip", "A tag named '%1' already exists.", tagName);
}
this->enableButtonOk(toolTip.isEmpty());
setLineEditErrorModeActive(!toolTip.isEmpty());
m_tagNameTextEdit->setToolTip(toolTip);
this->setButtonToolTip(KDialog::Ok, toolTip);
}
void TagDialog::setLineEditErrorModeActive(bool active)
{
m_tagNameTextEdit->setPalette(active ? m_errorColors : QPalette());
}
#include "moc_tagdialog.cpp"

View file

@ -0,0 +1,67 @@
/******************************************************************************
* Copyright (C) 2010 by Johannes Steffen <johannes.steffen@st.ovgu.de> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
******************************************************************************/
#ifndef TAGDIALOG_H
#define TAGDIALOG_H
#include <kdialog.h>
#include <QSet>
class KTextEdit;
class KLineEdit;
class KComboBox;
#include <QTextCodec>
#include <QRadioButton>
class TagDialog : public KDialog
{
Q_OBJECT
public:
TagDialog(QWidget* parent = 0);
/**
* Returns the tag message given by the user.
* @returns The tag message.
*/
QByteArray tagMessage() const;
/**
* Returns the tag name given by the user.
* @return The tag name.
*/
QString tagName() const;
/**
* @returns The name of the branch the tag should point to or HEAD if
the tag should point to the current HEAD.
*/
QString baseBranch() const;
private slots:
void setOkButtonState();
private:
inline void setLineEditErrorModeActive(bool active);
private:
QSet<QString> m_tagNames;
KTextEdit* m_tagMessageTextEdit;
KLineEdit* m_tagNameTextEdit;
KComboBox* m_branchComboBox;
QTextCodec* m_localCodec;
QPalette m_errorColors;
};
#endif // TAGDIALOG_H

View file

@ -0,0 +1,54 @@
project(fileviewhgplugin)
set(fileviewhgplugin_SRCS
fileviewhgplugin.cpp
renamedialog.cpp
commitdialog.cpp
hgwrapper.cpp
statuslist.cpp
branchdialog.cpp
tagdialog.cpp
updatedialog.cpp
clonedialog.cpp
createdialog.cpp
syncdialogbase.cpp
mergedialog.cpp
pushdialog.cpp
pulldialog.cpp
hgconfig.cpp
configdialog.cpp
commititemdelegate.cpp
commitinfowidget.cpp
pathselector.cpp
bundledialog.cpp
exportdialog.cpp
importdialog.cpp
servedialog.cpp
servewrapper.cpp
backoutdialog.cpp
config-widgets/generalconfig.cpp
config-widgets/pathconfig.cpp
config-widgets/ignorewidget.cpp
config-widgets/pluginsettings.cpp
)
kde4_add_kcfg_files(fileviewhgplugin_SRCS fileviewhgpluginsettings.kcfgc)
kde4_add_plugin(fileviewhgplugin ${fileviewhgplugin_SRCS})
target_link_libraries(fileviewhgplugin ${KDE4_KIO_LIBS} ${KDE4_KTEXTEDITOR_LIBS} konq)
install(
FILES fileviewhgplugin.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
install(
FILES fileviewhgpluginsettings.kcfg
DESTINATION ${KDE4_KCFG_INSTALL_DIR}
)
install(
TARGETS fileviewhgplugin
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)

View file

@ -0,0 +1,3 @@
#! /bin/sh
$EXTRACTRC *.kcfg >> rc.cpp
$XGETTEXT *.cpp -o $podir/fileviewhgplugin.pot

View file

@ -0,0 +1,226 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "backoutdialog.h"
#include "commitinfowidget.h"
#include "fileviewhgpluginsettings.h"
#include "hgwrapper.h"
#include <QtGui/QWidget>
#include <QtGui/QGroupBox>
#include <QtGui/QCheckBox>
#include <QtGui/QGridLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/qlistwidget.h>
#include <QtGui/QLabel>
#include <QtCore/QTextCodec>
#include <QtCore/QProcess>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kdebug.h>
HgBackoutDialog::HgBackoutDialog(QWidget *parent) :
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Backout"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Backout"));
this->enableButtonOk(false);
//
setupUI();
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->backoutDialogWidth(),
settings->backoutDialogHeight()));
// connections
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
connect(m_selectBaseCommitButton, SIGNAL(clicked()),
this, SLOT(slotSelectBaseChangeset()));
connect(m_selectParentCommitButton, SIGNAL(clicked()),
this, SLOT(slotSelectParentChangeset()));
connect(m_baseRevision, SIGNAL(textChanged(const QString&)),
this, SLOT(slotUpdateOkButton(const QString&)));
}
void HgBackoutDialog::setupUI()
{
m_mainGroup = new QGroupBox;
m_baseRevision = new KLineEdit;
m_parentRevision = new KLineEdit;
m_optMerge = new QCheckBox(i18nc("@label:checkbox",
"Merge with old dirstate parent after backout"));
m_selectParentCommitButton = new KPushButton(i18nc("@label:button",
"Select Changeset"));
m_selectBaseCommitButton = new KPushButton(i18nc("@label:button",
"Select Changeset"));
QGridLayout *mainGroupLayout = new QGridLayout;
mainGroupLayout->addWidget(new QLabel(i18nc("@label",
"Revision to Backout: ")), 0, 0);
mainGroupLayout->addWidget(m_baseRevision, 0, 1);
mainGroupLayout->addWidget(m_selectBaseCommitButton, 0, 2);
mainGroupLayout->addWidget(new QLabel(i18nc("@label",
"Parent Revision (optional): ")), 1, 0);
mainGroupLayout->addWidget(m_parentRevision, 1, 1);
mainGroupLayout->addWidget(m_selectParentCommitButton, 1, 2);
mainGroupLayout->addWidget(m_optMerge, 2, 0, 1, 0);
m_mainGroup->setLayout(mainGroupLayout);
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_mainGroup);
widget->setLayout(layout);
setMainWidget(widget);
}
void HgBackoutDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setBackoutDialogHeight(this->height());
settings->setBackoutDialogWidth(this->width());
settings->writeConfig();
}
void HgBackoutDialog::loadCommits()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update heads list
QProcess process;
process.setWorkingDirectory(hgWrapper->getBaseDir());
QStringList args;
args << QLatin1String("log");
args << QLatin1String("--template");
args << QLatin1String("{rev}\n{node|short}\n{branch}\n"
"{author}\n{desc|firstline}\n");
process.start(QLatin1String("hg"), args);
process.waitForFinished();
m_commitInfo->clear();
const int FINAL = 5;
char buffer[FINAL][1024];
int count = 0;
while (process.readLine(buffer[count], sizeof(buffer[count])) > 0) {
if (count == FINAL - 1) {
QString rev = QTextCodec::codecForLocale()->toUnicode(buffer[0]).trimmed();
QString changeset = QTextCodec::codecForLocale()->toUnicode(buffer[1]).trimmed();
QString branch = QTextCodec::codecForLocale()->toUnicode(buffer[2]).trimmed();
QString author = QTextCodec::codecForLocale()->toUnicode(buffer[3]).trimmed();
QString log = QTextCodec::codecForLocale()->toUnicode(buffer[4]).trimmed();
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, rev);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitInfo->addItem(item);
}
count = (count + 1)%FINAL;
}
}
QString HgBackoutDialog::selectChangeset()
{
KDialog diag;
diag.setCaption(i18nc("@title:window",
"Select Changeset"));
diag.setButtons(KDialog::Ok | KDialog::Cancel);
diag.setDefaultButton(KDialog::Ok);
diag.setButtonText(KDialog::Ok, i18nc("@action:button", "Select"));
diag.setMinimumWidth(700);
m_commitInfo = new HgCommitInfoWidget;
loadCommits();
diag.setMainWidget(m_commitInfo);
if (diag.exec() == KDialog::Accepted) {
return m_commitInfo->selectedChangeset();
}
return QString();
}
void HgBackoutDialog::slotSelectBaseChangeset()
{
QString changeset = selectChangeset();
if (!changeset.isEmpty()) {
m_baseRevision->setText(changeset);
}
}
void HgBackoutDialog::slotSelectParentChangeset()
{
QString changeset = selectChangeset();
if (!changeset.isEmpty()) {
m_parentRevision->setText(changeset);
}
}
void HgBackoutDialog::done(int r)
{
if (r == KDialog::Accepted) {
HgWrapper *hgw = HgWrapper::instance();
QStringList args;
args << QLatin1String("--rev");
args << m_baseRevision->text();
if (!m_parentRevision->text().isEmpty()) {
args << QLatin1String("--parent");
args << m_parentRevision->text();
}
if (m_optMerge->checkState() == Qt::Checked) {
args << QLatin1String("--merge");
}
if (hgw->executeCommandTillFinished(QLatin1String("backout"), args)) {
KMessageBox::information(this, hgw->readAllStandardOutput());
KDialog::done(r);
}
else {
KMessageBox::error(this, hgw->readAllStandardError());
}
}
else {
KDialog::done(r);
}
}
void HgBackoutDialog::slotUpdateOkButton(const QString &text)
{
kDebug() << "text";
enableButtonOk(!text.isEmpty());
}
#include "moc_backoutdialog.cpp"

View file

@ -0,0 +1,79 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HG_BACKOUT_DIALOG
#define HG_BACKOUT_DIALOG
#include <kdialog.h>
#include <QGroupBox>
#include <QCheckBox>
class KLineEdit;
class HgCommitInfoWidget;
class KPushButton;
/**
* Implements dialog for Mercurial's backout feature.
*/
class HgBackoutDialog : public KDialog
{
Q_OBJECT
public:
HgBackoutDialog(QWidget *parent = 0);
public slots:
void done(int r);
private slots:
void saveGeometry();
void slotSelectBaseChangeset();
void slotSelectParentChangeset();
void slotUpdateOkButton(const QString &text);
private:
void setupUI();
/**
* Find appropriate changesets in repository and show them in
* Commit Selector (CommitInfoWidget)
*/
void loadCommits();
/**
* Opens a dialog showing all changesets in a list and their respective
* information when highlighted.
*/
QString selectChangeset();
private:
QGroupBox *m_mainGroup;
HgCommitInfoWidget *m_commitInfo;
KPushButton *m_selectBaseCommitButton;
KLineEdit *m_baseRevision;
KPushButton *m_selectParentCommitButton;
KLineEdit *m_parentRevision;
QCheckBox *m_optMerge;
};
#endif /* HG_BACKOUT_DIALOG */

View file

@ -0,0 +1,147 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "branchdialog.h"
#include "hgwrapper.h"
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <kpushbutton.h>
#include <kcombobox.h>
#include <klocale.h>
#include <klineedit.h>
#include <kdebug.h>
#include <kmessagebox.h>
HgBranchDialog::HgBranchDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Branch"));
this->setButtons(KDialog::None);
// UI
QFrame *frame = new QFrame;
QVBoxLayout *vbox = new QVBoxLayout;
m_currentBranchLabel = new QLabel;
vbox->addWidget(m_currentBranchLabel);
m_branchComboBox = new KComboBox;
m_branchComboBox->setEditable(true);
vbox->addWidget(m_branchComboBox);
QHBoxLayout *buttonLayout = new QHBoxLayout;
m_createBranch = new KPushButton(i18n("Create New Branch"));
m_updateBranch = new KPushButton(i18n("Switch Branch"));
buttonLayout->addWidget(m_createBranch);
buttonLayout->addWidget(m_updateBranch);
vbox->addLayout(buttonLayout);
m_createBranch->setEnabled(false);
m_updateBranch->setEnabled(false);
frame->setLayout(vbox);
updateInitialDialog();
slotUpdateDialog(QString());
setMainWidget(frame);
slotUpdateDialog(m_branchComboBox->currentText());
QLineEdit *m_lineEdit = m_branchComboBox->lineEdit();
// connections
connect(m_createBranch, SIGNAL(clicked()),
this, SLOT(slotCreateBranch()));
connect(m_updateBranch, SIGNAL(clicked()),
this, SLOT(slotSwitch()));
connect(m_branchComboBox, SIGNAL(editTextChanged(const QString&)),
this, SLOT(slotUpdateDialog(const QString &)));
connect(m_lineEdit, SIGNAL(textChanged(const QString&)),
this, SLOT(slotUpdateDialog(const QString&)));
}
void HgBranchDialog::updateInitialDialog()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update label - current branch
QString out;
hgWrapper->executeCommand(QLatin1String("branch"), QStringList(), out);
out = i18n("<b>Current Branch: </b>") + out;
m_currentBranchLabel->setText(out);
// update combo box
m_branchList = hgWrapper->getBranches();
m_branchComboBox->addItems(m_branchList);
}
void HgBranchDialog::slotUpdateDialog(const QString &text)
{
// update pushbuttons
if (text.length() == 0) {
m_createBranch->setEnabled(false);
m_updateBranch->setEnabled(false);
}
else if (m_branchList.contains(text)) {
m_createBranch->setEnabled(false);
m_updateBranch->setEnabled(true);
}
else {
m_createBranch->setEnabled(true);
m_updateBranch->setEnabled(false);
}
}
void HgBranchDialog::slotSwitch()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString out;
QStringList args;
args << QLatin1String("-c");
args << m_branchComboBox->currentText();
if (hgWrapper->executeCommand(QLatin1String("update"), args, out)) {
//KMessageBox::information(this, i18n("Updated working directory!"));
done(KDialog::Ok);
}
else {
KMessageBox::error(this, i18n("Some error occurred"));
}
}
void HgBranchDialog::slotCreateBranch()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString out;
QStringList args;
args << m_branchComboBox->currentText();
if (hgWrapper->executeCommand(QLatin1String("branch"), args, out)) {
//KMessageBox::information(this, i18n("Created branch successfully!"));
done(KDialog::Ok);
}
else {
KMessageBox::error(this, i18n("Some error occurred"));
}
}
#include "moc_branchdialog.cpp"

View file

@ -0,0 +1,59 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGBRANCH_H
#define HGBRANCH_H
#include <QtCore/QString>
#include <kdialog.h>
class KComboBox;
class KPushButton;
#include <QLabel>
/**
* Implements dialog to list & create branches and update/switch working
* directory to differnt branch.
*/
class HgBranchDialog : public KDialog
{
Q_OBJECT
public:
HgBranchDialog(QWidget *parent = 0);
public slots:
void slotUpdateDialog(const QString &text);
void slotCreateBranch();
void slotSwitch();
private:
void updateInitialDialog();
private:
KComboBox *m_branchComboBox;
KPushButton *m_createBranch;
KPushButton *m_updateBranch;
QLabel *m_currentBranchLabel;
QStringList m_branchList;
};
#endif // HGBRANCH_H

View file

@ -0,0 +1,237 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "bundledialog.h"
#include "commitinfowidget.h"
#include "pathselector.h"
#include "fileviewhgpluginsettings.h"
#include "hgwrapper.h"
#include <QtGui/QWidget>
#include <QtGui/QGroupBox>
#include <QtGui/QCheckBox>
#include <QtGui/QGridLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/qlistwidget.h>
#include <QtGui/QLabel>
#include <QtCore/QTextCodec>
#include <QtCore/QProcess>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kdebug.h>
HgBundleDialog::HgBundleDialog(QWidget *parent) :
KDialog(parent, Qt::Dialog)
{
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Bundle"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Bundle"));
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->bundleDialogWidth(),
settings->bundleDialogHeight()));
//
setupUI();
// connections
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
connect(m_selectCommitButton, SIGNAL(clicked()),
this, SLOT(slotSelectChangeset()));
connect(m_allChangesets, SIGNAL(stateChanged(int)),
this, SLOT(slotAllChangesCheckToggled(int)));
}
void HgBundleDialog::setupUI()
{
QVBoxLayout *layout = new QVBoxLayout;
// main
m_pathSelect = new HgPathSelector;
m_baseRevision = new KLineEdit;
m_selectCommitButton = new KPushButton(i18nc("@label:button",
"Select Changeset"));
QLabel *baseRevisionLabel = new QLabel(i18nc("@label",
"Base Revision (optional): "));
m_allChangesets = new QCheckBox(i18nc("@label",
"Bundle all changesets in repository."));
QGridLayout *bodyLayout = new QGridLayout;
bodyLayout->addWidget(m_pathSelect, 0, 0, 2, 0);
bodyLayout->addWidget(baseRevisionLabel, 2, 0);
bodyLayout->addWidget(m_baseRevision, 2, 1);
bodyLayout->addWidget(m_selectCommitButton, 2, 2);
bodyLayout->addWidget(m_allChangesets, 3, 0, 2, 0);
m_mainGroup = new QGroupBox;
m_mainGroup->setLayout(bodyLayout);
layout->addWidget(m_mainGroup);
// options
m_optionGroup = new QGroupBox(i18nc("@label:group", "Options"));
m_optForce = new QCheckBox(i18nc("@label:checkbox",
"Run even when the destination is "
"unrelated (force)"));
m_optInsecure = new QCheckBox(i18nc("@label:checkbox",
"Do not verify server certificate"));
QVBoxLayout *optionLayout = new QVBoxLayout;
optionLayout->addWidget(m_optForce);
optionLayout->addWidget(m_optInsecure);
m_optionGroup->setLayout(optionLayout);
layout->addWidget(m_optionGroup);
//end options
QWidget *widget = new QWidget;
widget->setLayout(layout);
setMainWidget(widget);
}
void HgBundleDialog::done(int r)
{
if (r == KDialog::Accepted) {
QString result = KFileDialog::getSaveFileName();
if (result.length() > 0) {
createBundle(result);
KDialog::done(r);
}
}
else {
KDialog::done(r);
}
}
void HgBundleDialog::createBundle(const QString &fileName)
{
HgWrapper *hgw = HgWrapper::instance();
QStringList args;
if (m_allChangesets->checkState() == Qt::Checked) {
args << QLatin1String("--all");
}
else {
if (m_baseRevision->text().trimmed().length() > 0) {
args << QLatin1String("--base");
args << m_baseRevision->text().trimmed();
}
}
if (m_optForce->checkState() == Qt::Checked) {
args << QLatin1String("--force");
}
if (m_optInsecure->checkState() == Qt::Checked) {
args << QLatin1String("--insecure");
}
args << fileName;
args << m_pathSelect->remote();
hgw->executeCommand(QLatin1String("bundle"), args);
}
void HgBundleDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setBundleDialogHeight(this->height());
settings->setBundleDialogWidth(this->width());
settings->writeConfig();
}
void HgBundleDialog::loadCommits()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update heads list
QProcess process;
process.setWorkingDirectory(hgWrapper->getBaseDir());
QStringList args;
args << QLatin1String("log");
args << QLatin1String("--template");
args << QLatin1String("{rev}\n{node|short}\n{branch}\n"
"{author}\n{desc|firstline}\n");
process.start(QLatin1String("hg"), args);
process.waitForFinished();
m_commitInfo->clear();
const int FINAL = 5;
char buffer[FINAL][1024];
int count = 0;
while (process.readLine(buffer[count], sizeof(buffer[count])) > 0) {
if (count == FINAL - 1) {
QString rev = QTextCodec::codecForLocale()->toUnicode(buffer[0]).trimmed();
QString changeset = QTextCodec::codecForLocale()->toUnicode(buffer[1]).trimmed();
QString branch = QTextCodec::codecForLocale()->toUnicode(buffer[2]).trimmed();
QString author = QTextCodec::codecForLocale()->toUnicode(buffer[3]).trimmed();
QString log = QTextCodec::codecForLocale()->toUnicode(buffer[4]).trimmed();
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, rev);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitInfo->addItem(item);
}
count = (count + 1)%FINAL;
}
}
void HgBundleDialog::slotSelectChangeset()
{
KDialog diag;
diag.setCaption(i18nc("@title:window",
"Select Changeset"));
diag.setButtons(KDialog::Ok | KDialog::Cancel);
diag.setDefaultButton(KDialog::Ok);
diag.setButtonText(KDialog::Ok, i18nc("@action:button", "Select"));
diag.setMinimumWidth(700);
m_commitInfo = new HgCommitInfoWidget;
loadCommits();
diag.setMainWidget(m_commitInfo);
if (diag.exec() == KDialog::Accepted) {
m_baseRevision->setText(m_commitInfo->selectedChangeset());
}
}
void HgBundleDialog::slotAllChangesCheckToggled(int state)
{
if (state == Qt::Checked) {
m_selectCommitButton->setEnabled(false);
m_baseRevision->setEnabled(false);
}
else {
m_selectCommitButton->setEnabled(true);
m_baseRevision->setEnabled(true);
}
}
#include "moc_bundledialog.cpp"

View file

@ -0,0 +1,92 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGBUNDLEDIALOG_H
#define HGBUNDLEDIALOG_H
#include <kdialog.h>
#include <QGroupBox>
#include <QCheckBox>
class KLineEdit;
class HgCommitInfoWidget;
class HgPathSelector;
class KPushButton;
/**
* Dialog which implements bundle feature of Mercurial. Bundle enables
* user to creates a file containing all the selected/desired changesets
* in mercurial's internal format rather than patches.
*
* Changesets can either be selected by user or after being compared by
* remote repository selected.
*
*/
class HgBundleDialog : public KDialog
{
Q_OBJECT
public:
HgBundleDialog(QWidget *parent=0);
public slots:
void done(int r);
private slots:
void saveGeometry();
/**
* Opens a dialog listing all changeset from which user will select a
* changeset for base revision.
*/
void slotSelectChangeset();
void slotAllChangesCheckToggled(int state);
private:
void setupUI();
/**
* Creates bundle file.
*
* @param fileName Path to file where bundle will be created.
*/
void createBundle(const QString &fileName);
/**
* Find all changesets in respository and show them in Commit Selector in
* Base Changeset selector.
*/
void loadCommits();
private:
QGroupBox *m_mainGroup;
HgPathSelector *m_pathSelect;
HgCommitInfoWidget *m_commitInfo;
KPushButton *m_selectCommitButton;
KLineEdit *m_baseRevision;
QCheckBox *m_allChangesets;
//options
QGroupBox *m_optionGroup;
QCheckBox *m_optForce;
QCheckBox *m_optInsecure;
};
#endif /* HGBUNDLEDIALOG_H */

View file

@ -0,0 +1,248 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "clonedialog.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QGroupBox>
#include <QtGui/QGridLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <QtGui/QStackedLayout>
#include <QtGui/QApplication>
#include <QtGui/QCheckBox>
#include <QtCore/QTextCodec>
#include <kurl.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <ktextedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
HgCloneDialog::HgCloneDialog(const QString &directory, QWidget *parent):
KDialog(parent, Qt::Dialog),
m_cloned(false),
m_terminated(true),
m_workingDirectory(directory)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Clone"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Clone"));
this->enableButtonOk(false);
//////////////
// Setup UI //
//////////////
QGroupBox *urlGroup = new QGroupBox(i18n("URLs"));
QGridLayout *urlLayout = new QGridLayout;
QLabel *sourceLabel = new QLabel(i18nc("@label", "Source"));
QLabel *destLabel = new QLabel(i18nc("@lobel", "Destination"));
KPushButton *m_browse_dest = new KPushButton(i18nc("@button", "Browse"));
KPushButton *m_browse_source = new KPushButton(i18nc("@button", "Browse"));
m_source = new KLineEdit;
m_destination = new KLineEdit;
urlLayout->addWidget(sourceLabel, 0, 0);
urlLayout->addWidget(m_source, 0, 1);
urlLayout->addWidget(m_browse_source, 0, 2);
urlLayout->addWidget(destLabel, 1, 0);
urlLayout->addWidget(m_destination, 1, 1);
urlLayout->addWidget(m_browse_dest, 1, 2);
urlGroup->setLayout(urlLayout);
// Options Group
QGroupBox *optionGroup = new QGroupBox(i18nc("@label", "Options"));
QVBoxLayout *optionLayout = new QVBoxLayout;
m_optNoUpdate = new QCheckBox(i18n("Do not update the new working directory."));
m_optUsePull = new QCheckBox(i18n("Use pull protocol to copy metadata."));
m_optUseUncmprdTrans = new QCheckBox(i18n("Use uncompressed transfer."));
m_optNoVerifyServCert = new QCheckBox(i18n("Do not verify server certificate (ignoring web.cacerts config)."));
optionLayout->addWidget(m_optNoUpdate);
optionLayout->addWidget(m_optUsePull);
optionLayout->addWidget(m_optUseUncmprdTrans);
optionLayout->addWidget(m_optNoVerifyServCert);
optionGroup->setLayout(optionLayout);
// end options
QFrame *frame = new QFrame;
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(urlGroup);
mainLayout->addWidget(optionGroup);
mainLayout->addStretch();
frame->setLayout(mainLayout);
m_stackLayout = new QStackedLayout;
m_outputEdit = new KTextEdit;
m_outputEdit->setReadOnly(true);
m_outputEdit->setFontFamily(QLatin1String(KDE_DEFAULT_FIXED_FONT));
m_stackLayout->addWidget(frame);
m_stackLayout->addWidget(m_outputEdit);
QFrame *mainFrame = new QFrame;
mainFrame->setLayout(m_stackLayout);
m_stackLayout->setCurrentIndex(0);
setMainWidget(mainFrame);
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->cloneDialogWidth(),
settings->cloneDialogHeight()));
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
connect(m_source, SIGNAL(textChanged(const QString&)),
this, SLOT(slotUpdateOkButton()));
connect(m_browse_dest, SIGNAL(clicked()),
this, SLOT(slotBrowseDestClicked()));
connect(m_browse_source, SIGNAL(clicked()),
this, SLOT(slotBrowseSourceClicked()));
connect(&m_process, SIGNAL(started()), this, SLOT(slotCloningStarted()));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotCloningFinished(int, QProcess::ExitStatus)));
connect(&m_process, SIGNAL(readyReadStandardOutput()),
this, SLOT(slotUpdateCloneOutput()));
}
void HgCloneDialog::browseDirectory(KLineEdit *dest)
{
QString result = KFileDialog::getExistingDirectory();
if (result.length() > 0) {
dest->setText(result);
}
}
void HgCloneDialog::slotBrowseDestClicked()
{
browseDirectory(m_destination);
}
void HgCloneDialog::slotBrowseSourceClicked()
{
browseDirectory(m_source);
}
void HgCloneDialog::done(int r)
{
if (r == KDialog::Accepted && !m_cloned) {
// Will execute 'stdbuf' command to make the output of
// mercurial command line buffered and enable us to show
// output of cloning as soon as new line is available
QStringList args;
args << QLatin1String("-oL"); //argument for stdbuf.
args << QLatin1String("hg");
args << QLatin1String("clone");
args << QLatin1String("--verbose");
appendOptionArguments(args);
args << m_source->text();
if (!m_destination->text().isEmpty()) {
args << m_destination->text();
}
m_outputEdit->clear();
m_stackLayout->setCurrentIndex(1);
QApplication::processEvents();
enableButtonOk(false);
m_process.setWorkingDirectory(m_workingDirectory);
m_process.start(QLatin1String("stdbuf"), args);
}
else if (r == KDialog::Accepted && m_cloned) {
KDialog::done(r);
}
else {
if (m_process.state() == QProcess::Running) {
KMessageBox::error(this, i18n("Terminating cloning!"));
enableButtonOk(true);
m_terminated = true;
m_process.terminate();
m_stackLayout->setCurrentIndex(0);
}
else {
KDialog::done(r);
}
}
}
void HgCloneDialog::slotCloningStarted()
{
m_terminated = false;
}
void HgCloneDialog::slotUpdateCloneOutput()
{
m_outputEdit->insertPlainText(QTextCodec::codecForLocale()->toUnicode(m_process.readAllStandardOutput()));
}
void HgCloneDialog::slotCloningFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitCode == 0 && exitStatus == QProcess::NormalExit) {
m_cloned = true;
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Close"));
this->enableButtonOk(true);
}
else if (!m_terminated) {
KMessageBox::error(this, i18nc("@message:error",
"Error Cloning Repository!"));
}
}
void HgCloneDialog::appendOptionArguments(QStringList &args)
{
if (m_optNoUpdate->checkState() == Qt::Checked) {
args << QLatin1String("-U");
}
if (m_optUsePull->checkState() == Qt::Checked) {
args << QLatin1String("--pull");
}
if (m_optUseUncmprdTrans->checkState() == Qt::Checked) {
args << QLatin1String("--uncompressed");
}
if (m_optNoVerifyServCert->checkState() == Qt::Checked) {
args << QLatin1String("--insecure");
}
}
void HgCloneDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setCloneDialogHeight(this->height());
settings->setCloneDialogWidth(this->width());
settings->writeConfig();
}
void HgCloneDialog::slotUpdateOkButton()
{
if (m_source->text().length() > 0) {
enableButtonOk(true);
}
else {
enableButtonOk(false);
}
}
#include "moc_clonedialog.cpp"

View file

@ -0,0 +1,92 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCLONEDILAOG_H
#define HGCLONEDILAOG_H
#include <QtCore/QString>
#include <QtCore/QProcess>
#include <kdialog.h>
class KLineEdit;
class KPushButton;
class KTextEdit;
#include <QStackedLayout>
#include <QCheckBox>
//TODO: Enable to enter username/passwords if not found in config as well
// as override within dialog
/**
* Implements dialog to clone repository.
*/
class HgCloneDialog : public KDialog
{
Q_OBJECT
public:
HgCloneDialog(const QString &directory, QWidget *parent = 0);
void setWorkingDirectory(const QString &directory);
private slots:
void saveGeometry();
/**
* Enables dialog's Ok button when user has entered some input in
* source LineEdit
*/
void slotUpdateOkButton();
void slotBrowseDestClicked();
void slotBrowseSourceClicked();
void slotCloningStarted();
void slotCloningFinished(int exitCode, QProcess::ExitStatus);
/**
* Show output of clone operation in TextEdit component.
*/
void slotUpdateCloneOutput();
private:
void done(int r);
void browseDirectory(KLineEdit *dest);
void appendOptionArguments(QStringList &args);
private:
KLineEdit *m_source;
KLineEdit *m_destination;
KPushButton *m_browse_dest;
KPushButton *m_browse_source;
KTextEdit *m_outputEdit;
QStackedLayout *m_stackLayout;
bool m_cloned;
bool m_terminated;
QString m_workingDirectory;
QProcess m_process;
// option checkboxes
QCheckBox *m_optNoUpdate;
QCheckBox *m_optUsePull;
QCheckBox *m_optUseUncmprdTrans;
QCheckBox *m_optNoVerifyServCert;
};
#endif // HGCLONEDILAOG_H

View file

@ -0,0 +1,370 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "commitdialog.h"
#include "hgwrapper.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <QtGui/QActionGroup>
#include <QtGui/QPlainTextEdit>
#include <KTextEditor/Document>
#include <KTextEditor/View>
#include <KTextEditor/Editor>
#include <KTextEditor/EditorChooser>
#include <kmessagebox.h>
#include <kmenu.h>
#include <kaction.h>
#include <klineedit.h>
#include <kurl.h>
#include <kpushbutton.h>
#include <klocale.h>
HgCommitDialog::HgCommitDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Commit"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Commit"));
this->enableButtonOk(false); // since commit message is empty when loaded
// To show diff between commit
KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
if (!editor) {
KMessageBox::error(this,
i18n("A KDE text-editor component could not be found;"
"\nplease check your KDE installation."));
return;
}
m_fileDiffDoc = editor->createDocument(0);
m_fileDiffView = qobject_cast<KTextEditor::View*>(m_fileDiffDoc->createView(this));
m_fileDiffDoc->setReadWrite(false);
// Setup actions
m_useCurrentBranch= new KAction(this);
m_useCurrentBranch->setCheckable(true);
m_useCurrentBranch->setText(i18nc("@action:inmenu",
"Commit to current branch"));
m_newBranch = new KAction(this);
m_newBranch->setCheckable(true);
m_newBranch->setText(i18nc("@action:inmenu",
"Create new branch"));
m_closeBranch = new KAction(this);
m_closeBranch->setCheckable(true);
m_closeBranch->setText(i18nc("@action:inmenu",
"Close current branch"));
m_branchMenu = new KMenu(this);
m_branchMenu->addAction(m_useCurrentBranch);
m_branchMenu->addAction(m_newBranch);
m_branchMenu->addAction(m_closeBranch);
QActionGroup *branchActionGroup = new QActionGroup(this);
branchActionGroup->addAction(m_useCurrentBranch);
branchActionGroup->addAction(m_newBranch);
branchActionGroup->addAction(m_closeBranch);
m_useCurrentBranch->setChecked(true);
connect(branchActionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(slotBranchActions(QAction *)));
//////////////
// Setup UI //
//////////////
// Top bar of buttons
QHBoxLayout *topBarLayout = new QHBoxLayout;
m_copyMessageButton = new KPushButton(i18n("Copy Message"));
m_branchButton = new KPushButton(i18n("Branch"));
m_copyMessageMenu = new KMenu(this);
createCopyMessageMenu();
topBarLayout->addWidget(new QLabel(getParentForLabel()));
topBarLayout->addStretch();
topBarLayout->addWidget(m_branchButton);
topBarLayout->addWidget(m_copyMessageButton);
m_branchButton->setMenu(m_branchMenu);
m_copyMessageButton->setMenu(m_copyMessageMenu);
// the commit box itself
QGroupBox *messageGroupBox = new QGroupBox;
QVBoxLayout *commitLayout = new QVBoxLayout;
m_commitMessage = new QPlainTextEdit;
commitLayout->addWidget(m_commitMessage);
messageGroupBox->setTitle(i18nc("@title:group", "Commit Message"));
messageGroupBox->setLayout(commitLayout);
// Show diff here
QGroupBox *diffGroupBox = new QGroupBox;
QVBoxLayout *diffLayout = new QVBoxLayout(diffGroupBox);
diffLayout->addWidget(m_fileDiffView);
diffGroupBox->setTitle(i18nc("@title:group", "Diff/Content"));
diffGroupBox->setLayout(diffLayout);
// Set up layout for Status, Commit and Diff boxes
QGridLayout *bodyLayout = new QGridLayout;
m_statusList = new HgStatusList;
bodyLayout->addWidget(m_statusList, 0, 0, 0, 1);
bodyLayout->addWidget(messageGroupBox, 0, 1);
bodyLayout->addWidget(diffGroupBox, 1, 1);
bodyLayout->setColumnStretch(0, 1);
bodyLayout->setColumnStretch(1, 2);
bodyLayout->setRowStretch(0, 1);
bodyLayout->setRowStretch(1, 1);
// Set up layout and container for main dialog
QFrame *frame = new QFrame;
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topBarLayout);
mainLayout->addLayout(bodyLayout);
frame->setLayout(mainLayout);
setMainWidget(frame);
slotBranchActions(m_useCurrentBranch);
slotInitDiffOutput(); // initialise with whole repo diff
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->commitDialogWidth(),
settings->commitDialogHeight()));
//
connect(m_statusList, SIGNAL(itemSelectionChanged(const char, const QString &)),
this, SLOT(slotItemSelectionChanged(const char, const QString &)));
connect(m_commitMessage, SIGNAL(textChanged()),
this, SLOT(slotMessageChanged()));
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
}
QString HgCommitDialog::getParentForLabel()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString line("<b>parents:</b> ");
line += hgWrapper->getParentsOfHead();
return line;
}
void HgCommitDialog::slotInitDiffOutput()
{
m_fileDiffDoc->setReadWrite(true);
m_fileDiffDoc->setModified(false);
m_fileDiffDoc->closeUrl(true);
QString diffOut;
HgWrapper *hgWrapper = HgWrapper::instance();
hgWrapper->executeCommand(QLatin1String("diff"), QStringList(), diffOut);
m_fileDiffDoc->setHighlightingMode("diff");
m_fileDiffDoc->setText(diffOut);
m_fileDiffView->setCursorPosition( KTextEditor::Cursor(0, 0) );
m_fileDiffDoc->setReadWrite(false);
}
void HgCommitDialog::slotItemSelectionChanged(const char status,
const QString &fileName)
{
m_fileDiffDoc->setReadWrite(true);
m_fileDiffDoc->setModified(false);
m_fileDiffDoc->closeUrl(true);
if (status != '?') {
QStringList arguments;
QString diffOut;
HgWrapper *hgWrapper = HgWrapper::instance();
arguments << fileName;
hgWrapper->executeCommand(QLatin1String("diff"), arguments, diffOut);
m_fileDiffDoc->setText(diffOut);
m_fileDiffDoc->setHighlightingMode("diff");
}
else {
KUrl url(HgWrapper::instance()->getBaseDir());
url.addPath(fileName);
m_fileDiffDoc->openUrl(url);
}
m_fileDiffDoc->setReadWrite(false);
m_fileDiffView->setCursorPosition( KTextEditor::Cursor(0, 0) );
}
void HgCommitDialog::slotMessageChanged()
{
enableButtonOk(!m_commitMessage->toPlainText().isEmpty());
}
void HgCommitDialog::done(int r)
{
if (r == KDialog::Accepted) {
QStringList files;
if (m_statusList->getSelectionForCommit(files)) {
HgWrapper *hgWrapper = HgWrapper::instance();
if (m_branchAction == NewBranch) {
if (!hgWrapper->createBranch(m_newBranchName)) {
KMessageBox::error(this,
i18n("Could not create branch! Aborting commit!"));
return;
}
}
bool success = hgWrapper->commit(m_commitMessage->toPlainText(),
files, m_branchAction==CloseBranch);
if (success) {
KDialog::done(r);
}
else {
KMessageBox::error(this, i18n("Commit unsuccessful!"));
}
}
else {
KMessageBox::error(this, i18n("No files for commit!"));
}
}
else {
KDialog::done(r);
}
}
void HgCommitDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setCommitDialogHeight(this->height());
settings->setCommitDialogWidth(this->width());
settings->writeConfig();
}
void HgCommitDialog::slotBranchActions(QAction *action)
{
if (action == m_useCurrentBranch) {
m_branchAction = NoChanges;
m_branchButton->setText(i18n("Branch: Current Branch"));
}
else if (action == m_newBranch) {
NewBranchDialog diag;
if (diag.exec() == KDialog::Accepted) {
m_branchAction = NewBranch;
m_newBranchName = diag.getBranchName();
m_branchButton->setText(i18n("Branch: ") + m_newBranchName);
}
else { // restore previous check state
if (m_branchAction == NoChanges) {
m_useCurrentBranch->setChecked(true);
}
else if (m_branchAction == CloseBranch) {
m_closeBranch->setChecked(true);
}
}
}
else if (action == m_closeBranch) {
m_branchAction = CloseBranch;
m_branchButton->setText(i18n("Branch: Close Current"));
}
}
/*****************/
/* Branch Dialog */
/*****************/
NewBranchDialog::NewBranchDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Commit: New Branch"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->enableButtonOk(false); // since commit message is empty when loaded
m_branchList = HgWrapper::instance()->getBranches();
QLabel *message = new QLabel(i18nc("@label", "Enter new branch name"));
m_branchNameInput = new KLineEdit;
m_errorLabel = new QLabel;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(message);
layout->addWidget(m_branchNameInput);
layout->addWidget(m_errorLabel);
QFrame *frame = new QFrame;
frame->setLayout(layout);
setMainWidget(frame);
connect(m_branchNameInput, SIGNAL(textChanged(const QString&)),
this, SLOT(slotTextChanged(const QString&)));
}
void NewBranchDialog::slotTextChanged(const QString &text)
{
if (m_branchList.contains(text)) {
m_errorLabel->setText(i18nc("@label", "<b>Branch already exists!</b>"));
enableButtonOk(false);
}
else if (text.length() > 0) {
m_errorLabel->clear();
enableButtonOk(true);
}
else {
m_errorLabel->setText(i18nc("@label", "<b>Enter some text!</b>"));
enableButtonOk(false);
}
}
QString NewBranchDialog::getBranchName() const
{
return m_branchNameInput->text();
}
void HgCommitDialog::createCopyMessageMenu()
{
QActionGroup *actionGroup = new QActionGroup(this);
connect(actionGroup, SIGNAL(triggered(QAction *)),
this, SLOT(slotInsertCopyMessage(QAction *)));
QStringList args;
args << QLatin1String("--limit");
args << QLatin1String("5");
args << QLatin1String("--template");
args << QLatin1String("{desc|short}\n");
HgWrapper *hgw = HgWrapper::instance();
QString output;
hgw->executeCommand(QLatin1String("log"), args, output);
QStringList messages = output.split('\n', QString::SkipEmptyParts);
foreach (QString msg, messages) {
QAction *action = m_copyMessageMenu->addAction(msg);
actionGroup->addAction(action);
}
}
void HgCommitDialog::slotInsertCopyMessage(QAction *action)
{
m_commitMessage->insertPlainText(action->text());
}
#include "moc_commitdialog.cpp"

View file

@ -0,0 +1,132 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCOMMITDIALOG_H
#define HGCOMMITDIALOG_H
#include "statuslist.h"
#include <QtCore/QString>
#include <kdialog.h>
#include <QPlainTextEdit>
class KAction;
class KMenu;
#include <QLabel>
namespace KTextEditor {
class View;
class Document;
};
// TODO: Filter in HgStatusList.
/**
* Implements dialog for Commit changes. User is presented with a list of
* changes/added/removed files, their diffs, a TextEdit to enter
* commit message, options to change/create/close branch and last 5 commit
* messages.
*/
class HgCommitDialog : public KDialog
{
Q_OBJECT
public:
HgCommitDialog(QWidget *parent = 0);
private slots:
/**
* Shows diff of selected file in a KTextEditor widget when user selects
* one of the entry in HgStatusList widget.
*/
void slotItemSelectionChanged(const char status, const QString &fileName);
/**
* Will enable 'Ok' button of dialog if some message text is available or
* disables it.
*/
void slotMessageChanged();
void saveGeometry();
void slotBranchActions(QAction *action);
/**
* Shows diff of whole working directory together in KTextEditor widget.
* Equivalent to plain 'hg diff'
*/
void slotInitDiffOutput();
void slotInsertCopyMessage(QAction *action);
private:
QString getParentForLabel();
void createCopyMessageMenu();
void done(int r);
private:
QString m_hgBaseDir;
QPlainTextEdit *m_commitMessage;
HgStatusList *m_statusList;
KTextEditor::View *m_fileDiffView;
KTextEditor::Document *m_fileDiffDoc;
KPushButton *m_branchButton;
KPushButton *m_copyMessageButton;
KAction *m_closeBranch;
KAction *m_newBranch;
KAction *m_useCurrentBranch;
KMenu *m_branchMenu;
KMenu *m_copyMessageMenu;
/** What will commit do with branch.
*
* CloseBranch: Close the current branch
* NewBranch : Creates new branch for this commit
* NoChanges : No changes to branch are made.
*/
enum {CloseBranch, NewBranch, NoChanges} m_branchAction;
QString m_newBranchName;
};
/**
* Dialog which asks for the new branch name in commit dialog
*/
class NewBranchDialog : public KDialog
{
Q_OBJECT
public:
NewBranchDialog(QWidget *parent = 0);
QString getBranchName() const;
private slots:
void slotTextChanged(const QString &text);
private:
QLabel *m_errorLabel;
KLineEdit *m_branchNameInput;
QStringList m_branchList;
};
#endif // HGCOMMITDIALOG_H

View file

@ -0,0 +1,134 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "commitinfowidget.h"
#include "commititemdelegate.h"
#include "hgwrapper.h"
#include <QtCore/QString>
#include <QtGui/QHBoxLayout>
#include <QtGui/QListWidget>
#include <KTextEditor/Document>
#include <KTextEditor/View>
#include <KTextEditor/Editor>
#include <KTextEditor/EditorChooser>
#include <KTextEditor/Cursor>
#include <kmessagebox.h>
#include <klocale.h>
HgCommitInfoWidget::HgCommitInfoWidget(QWidget *parent) :
QWidget(parent)
{
setupUI();
connect(m_commitListWidget, SIGNAL(itemSelectionChanged()),
this, SLOT(slotUpdateInfo()));
}
void HgCommitInfoWidget::setupUI()
{
m_commitListWidget = new QListWidget;
m_commitListWidget->setItemDelegate(new CommitItemDelegate);
KTextEditor::Editor *editor = KTextEditor::EditorChooser::editor();
if (!editor) {
KMessageBox::error(this,
i18n("A KDE text-editor component could not be found;"
"\nplease check your KDE installation."));
return;
}
m_editorDoc = editor->createDocument(0);
m_editorView = qobject_cast<KTextEditor::View*>(m_editorDoc->createView(this));
m_editorDoc->setReadWrite(false);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(m_commitListWidget, 1);
layout->addWidget(m_editorView, 2);
setLayout(layout);
}
void HgCommitInfoWidget::addItem(const QString &revision,
const QString &changeset,
const QString &branch,
const QString &author,
const QString &log)
{
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, revision);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitListWidget->addItem(item);
}
void HgCommitInfoWidget::addItem(QListWidgetItem *item)
{
m_commitListWidget->addItem(item);
}
QListWidgetItem* HgCommitInfoWidget::currentItem() const
{
return m_commitListWidget->currentItem();
}
const QString HgCommitInfoWidget::selectedChangeset() const
{
return m_commitListWidget->currentItem()->data(Qt::DisplayRole).toString();
}
void HgCommitInfoWidget::clear() const
{
m_commitListWidget->clear();
}
void HgCommitInfoWidget::slotUpdateInfo()
{
HgWrapper *hgw = HgWrapper::instance();
QString changeset = selectedChangeset();
QString output;
QStringList args;
args << QLatin1String("-p");
args << QLatin1String("-v");
args << QLatin1String("-r");
args << changeset;
hgw->executeCommand(QLatin1String("log"), args, output);
m_editorDoc->setReadWrite(true);
m_editorDoc->setModified(false);
m_editorDoc->closeUrl(true);
m_editorDoc->setText(output);
m_editorDoc->setHighlightingMode("diff");
m_editorView->setCursorPosition( KTextEditor::Cursor(0, 0) );
m_editorDoc->setReadWrite(false);
}
void HgCommitInfoWidget::setSelectionMode(QAbstractItemView::SelectionMode mode)
{
m_commitListWidget->setSelectionMode(mode);
}
QList<QListWidgetItem*> HgCommitInfoWidget::selectedItems() const
{
return m_commitListWidget->selectedItems();
}

View file

@ -0,0 +1,122 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCOMMITINFOWIDGET_H
#define HGCOMMITINFOWIDGET_H
#include <QtGui/QWidget>
#include <QtGui/QAbstractItemView>
#include <QtCore/QList>
namespace KTextEditor {
class View;
class Document;
};
#include <QListWidget>
#include <QListWidgetItem>
/**
* Shows Changesets using a custom deltegate CommitItemDelegate. Shows
* changeset information in a KTextEditor widget when a changeset entry is
* highlighted.
* */
class HgCommitInfoWidget : public QWidget
{
Q_OBJECT
public:
HgCommitInfoWidget(QWidget *parent=0);
/**
* Adds a new entry in the ListWidget with the chageset parameters
* provided in its parameter.
*
* @param revision Revision number of changeset
* @param changeset Changeset identification hash (shortened)
* @param author Author of the CommitItemDelegate
* @param log Commit Message of that changeset
*
*/
void addItem(const QString &revision,
const QString &changeset,
const QString &branch,
const QString &author,
const QString &log);
/**
* Adds a new QListWidgetItem into list. Expects the changeset information
* in stored in different roles of data.
*
* DisplayRole => Changeset Identification Hash
* UserRole + 1 => Revision Number
* UserRole + 2 => Branch
* UserRole + 3 => Author
* UserRole + 4 => Log/Commit Message
*
* @param item Pointer to the QListWidgetItem object to be added
*/
void addItem(QListWidgetItem *item);
/**
* Returns changeset identification hash of selected changeset in ListWidget.
*
* @return String containing the changeset identification hash of selected
* chageset
*
*/
const QString selectedChangeset() const;
/**
* @return Returns a list of selected changesets
*/
QList<QListWidgetItem*> selectedItems() const;
/**
* @return Returns pointer to QListWidgetItem of selected changeset.
*/
QListWidgetItem* currentItem() const;
/**
* Calls QListWidget::setSelectionMode(QAbstractItemView::SelectionMode)
* on the m_commitListWidget
*/
void setSelectionMode(QAbstractItemView::SelectionMode mode);
/**
* Clears all entries in m_commitListWidget
*/
void clear() const;
private slots:
/**
* Show selected changeset information when an entry is selected
*/
void slotUpdateInfo();
private:
void setupUI();
private:
KTextEditor::View *m_editorView;
KTextEditor::Document *m_editorDoc;
QListWidget *m_commitListWidget;
};
#endif /* HGCOMMITINFOWIDGET_H */

View file

@ -0,0 +1,90 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "commititemdelegate.h"
#include <QtGui/QPainter>
#include <QtGui/QFontMetrics>
CommitItemDelegate::CommitItemDelegate(QObject *parent) :
QItemDelegate(parent)
{
}
void CommitItemDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QString changeset = index.data(Qt::DisplayRole).toString();
QString revision = index.data(Qt::UserRole + 1).toString();
QString branch = index.data(Qt::UserRole + 2).toString();
QString authorName = index.data(Qt::UserRole + 3).toString();
QString commitLog = index.data(Qt::UserRole + 4).toString();
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
}
QFont font = option.font;
QFontMetrics fm(font);
QRect rect = option.rect.adjusted(4, 4, 4, 4);
QString top;
if (!revision.isEmpty()) {
top = QString("%1:").arg(revision);
}
top += changeset;
if (!branch.isEmpty()) {
top += QString(" (%1)").arg(branch);
}
font.setBold(true);
painter->setFont(font);
painter->drawText(rect, Qt::AlignLeft, top);
font.setPixelSize(0.60f * static_cast<float>(fm.height()));
font.setBold(false);
painter->setFont(font);
rect = rect.adjusted(0, fm.height(), 0, fm.height());
painter->drawText(rect, Qt::AlignLeft, authorName, &rect);
int fs = 0.60f * static_cast<float>(fm.height());
font.setPixelSize(fs);
font.setBold(false);
painter->setFont(font);
rect = rect.adjusted(0, fs+4, 0, fs+4);
painter->drawText(rect, Qt::AlignLeft, commitLog, &rect);
}
QSize CommitItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = QItemDelegate::sizeHint(option, index);
QFont font = option.font;
font.setBold(true);
QFontMetrics fm(font);
int height = static_cast<float>(option.fontMetrics.height()) * (1.2f) + fm.height() + 15;
size.setHeight(height);
return size;
}
#include "moc_commititemdelegate.cpp"

View file

@ -0,0 +1,46 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef COMMITITEMDELEGATE_H
#define COMMITITEMDELEGATE_H
#include <QItemDelegate>
/**
* Custom Delgate to show Commit info in three lines
* - Revision:Changeset (branch)
* - Author
* - Commit Log | First Line
*/
class CommitItemDelegate : public QItemDelegate
{
Q_OBJECT
public:
CommitItemDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
signals:
public slots:
};
#endif // COMMITITEMDELEGATE_H

View file

@ -0,0 +1,97 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "generalconfig.h"
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtCore/QString>
#include <QtGui/QCheckBox>
#include <klineedit.h>
#include <kpushbutton.h>
#include <klocale.h>
HgGeneralConfigWidget::HgGeneralConfigWidget(HgConfig::ConfigType type, QWidget *parent):
QWidget(parent),
m_configType(type)
{
setupUI();
loadConfig();
}
void HgGeneralConfigWidget::setupUI()
{
m_userEdit = new KLineEdit;
m_editorEdit = new KLineEdit;
m_mergeEdit = new KLineEdit;
m_verboseCheck = new QCheckBox(i18nc("@label:checkbox", "Verbose Output"));
QLabel *userLabel = new QLabel(i18nc("@label", "Username"));
QLabel *editorLabel = new QLabel(i18nc("@label", "Default Editor"));
QLabel *mergeLabel = new QLabel(i18nc("@label", "Default Merge Tool"));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(userLabel, 0, 0);
mainLayout->addWidget(m_userEdit, 0, 1);
mainLayout->addWidget(editorLabel, 1, 0);
mainLayout->addWidget(m_editorEdit, 1, 1);
mainLayout->addWidget(mergeLabel, 2, 0);
mainLayout->addWidget(m_mergeEdit, 2, 1);
mainLayout->addWidget(m_verboseCheck, 3, 0, 2, 0);
mainLayout->setRowStretch(mainLayout->rowCount(), 1);
setLayout(mainLayout);
}
void HgGeneralConfigWidget::loadConfig()
{
HgConfig hgc(m_configType);
m_userEdit->setText(hgc.username());
m_editorEdit->setText(hgc.editor());
m_mergeEdit->setText(hgc.merge());
QString verbose = hgc.property(QLatin1String("ui"), QLatin1String("verobose"));
if (verbose.isEmpty() || verbose == "False") {
m_verboseCheck->setChecked(false);
}
else if (verbose == "True") {
m_verboseCheck->setChecked(true);
}
}
void HgGeneralConfigWidget::saveConfig()
{
HgConfig hgc(m_configType);
hgc.setUsername(m_userEdit->text());
hgc.setEditor(m_editorEdit->text());
hgc.setMerge(m_mergeEdit->text());
if (m_verboseCheck->checkState() == Qt::Checked) {
hgc.setProperty(QLatin1String("ui"), QLatin1String("verbose"),
QLatin1String("True"));
}
else {
hgc.setProperty(QLatin1String("ui"), QLatin1String("verbose"),
QLatin1String("False"));
}
}
#include "moc_generalconfig.cpp"

View file

@ -0,0 +1,60 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGGENERAL_CONFIG_WIDGET_H
#define HGGENERAL_CONFIG_WIDGET_H
#include <QtGui/QWidget>
#include "hgconfig.h"
class KLineEdit;
#include <QCheckBox>
/**
* General configuration options, usually found [ui] group of hgrc file.
* Can be used with both, repository hgrc as well as global hgrc
*/
class HgGeneralConfigWidget : public QWidget
{
Q_OBJECT
public:
/**
* @param type Which configuration file to use, Repo or Global
*/
HgGeneralConfigWidget(HgConfig::ConfigType type, QWidget *parent = 0);
public slots:
void saveConfig();
void loadConfig();
private:
void setupUI();
private:
KLineEdit *m_userEdit;
KLineEdit *m_editorEdit;
KLineEdit *m_mergeEdit;
QCheckBox *m_verboseCheck;
HgConfig::ConfigType m_configType;
};
#endif // HGGENERAL_CONFIG_WIDGET_H

View file

@ -0,0 +1,185 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "ignorewidget.h"
#include "../hgwrapper.h"
#include <QtGui/QListWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QInputDialog>
#include <QtCore/QString>
#include <QtCore/QFile>
#include <QtCore/QList>
#include <QtCore/QTextStream>
#include <kurl.h>
#include <kpushbutton.h>
#include <klocale.h>
#include <kdebug.h>
#include <kmessagebox.h>
HgIgnoreWidget::HgIgnoreWidget(QWidget *parent) :
QWidget(parent)
{
setupUI();
loadConfig();
}
void HgIgnoreWidget::setupUI()
{
QVBoxLayout *sideBar = new QVBoxLayout;
m_addFiles = new KPushButton(i18nc("@label:button", "Add Files"));
m_addPattern = new KPushButton(i18nc("@label:button", "Add Pattern"));
m_editEntry = new KPushButton(i18nc("@label:button", "Edit Entry"));
m_removeEntries = new KPushButton(i18nc("@label:button", "Remove Entries"));
sideBar->addWidget(m_addFiles);
sideBar->addWidget(m_addPattern);
sideBar->addWidget(m_editEntry);
sideBar->addWidget(m_removeEntries);
sideBar->addStretch();
m_ignoreTable = new QListWidget;
m_untrackedList = new QListWidget;
setupUntrackedList();
m_ignoreTable->setSelectionMode(QListWidget::ExtendedSelection);
m_untrackedList->setSelectionMode(QListWidget::ExtendedSelection);
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(m_untrackedList);
mainLayout->addWidget(m_ignoreTable);
mainLayout->addLayout(sideBar);
setLayout(mainLayout);
connect(m_addFiles, SIGNAL(clicked()), this, SLOT(slotAddFiles()));
connect(m_removeEntries, SIGNAL(clicked()), this, SLOT(slotRemoveEntries()));
connect(m_addPattern, SIGNAL(clicked()), this, SLOT(slotAddPattern()));
connect(m_editEntry, SIGNAL(clicked()), this, SLOT(slotEditEntry()));
}
void HgIgnoreWidget::setupUntrackedList()
{
HgWrapper *hgw = HgWrapper::instance();
QStringList args;
args << QLatin1String("--unknown");
QString output;
hgw->executeCommand(QLatin1String("status"), args, output);
QStringList result = output.split('\n', QString::SkipEmptyParts);
foreach (QString file, result) {
m_untrackedList->addItem(file.mid(2));
}
}
void HgIgnoreWidget::loadConfig()
{
KUrl url(HgWrapper::instance()->getBaseDir());
url.addPath(QLatin1String(".hgignore"));
QFile file(url.path());
if (!file.open(QFile::ReadOnly)) {
return;
}
QTextStream fileStream(&file);
do {
QString buffer;
buffer = fileStream.readLine();
if (!buffer.isEmpty()) {
m_ignoreTable->addItem(buffer);
}
} while (!fileStream.atEnd());
file.close();
}
void HgIgnoreWidget::saveConfig()
{
KUrl url(HgWrapper::instance()->getBaseDir());
url.addPath(QLatin1String(".hgignore"));
QFile file(url.path());
if (!file.open(QFile::WriteOnly | QFile::Truncate)) {
return;
}
QTextStream fileStream(&file);
int count = m_ignoreTable->count();
for (int i=0; i<count; i++) {
QListWidgetItem *item = m_ignoreTable->item(i);
fileStream << item->text() << QLatin1String("\n");
}
file.close();
}
void HgIgnoreWidget::slotAddFiles()
{
QList<QListWidgetItem*> selectedItems = m_untrackedList->selectedItems();
foreach (QListWidgetItem *item, selectedItems) {
m_ignoreTable->addItem(item->text());
m_untrackedList->takeItem(m_untrackedList->row(item));
}
}
void HgIgnoreWidget::slotAddPattern()
{
bool ok;
QString input = QInputDialog::getText(this,
i18nc("@title:dialog", "Add Pattern"),
QString(),
QLineEdit::Normal,
QString(),
&ok);
if (ok && !input.isEmpty()) {
m_ignoreTable->addItem(input);
}
}
void HgIgnoreWidget::slotRemoveEntries()
{
QList<QListWidgetItem*> selectedItems = m_ignoreTable->selectedItems();
foreach (QListWidgetItem *item, selectedItems) {
m_ignoreTable->takeItem(m_ignoreTable->row(item));
}
}
void HgIgnoreWidget::slotEditEntry()
{
if (m_ignoreTable->currentItem() == 0) {
KMessageBox::error(this, i18nc("@message:error",
"No entry selected for edit!"));
return;
}
bool ok;
QString input = QInputDialog::getText(this,
i18nc("@title:dialog", "Edit Pattern"),
QString(),
QLineEdit::Normal,
m_ignoreTable->currentItem()->text(),
&ok);
if (ok && !input.isEmpty()) {
m_ignoreTable->currentItem()->setText(input);
}
}
#include "moc_ignorewidget.cpp"

View file

@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCONFIG_IGNOREWIDGET_H
#define HGCONFIG_IGNOREWIDGET_H
#include <QtGui/QWidget>
#include <QListWidget>
class KPushButton;
#include <QInputDialog>
/**
* Widget to manage ignored files. Used .hgignore file in repository.
* Repository only configuration
*/
class HgIgnoreWidget : public QWidget
{
Q_OBJECT
public:
HgIgnoreWidget(QWidget *parent = 0);
void loadConfig();
void saveConfig();
private slots:
void slotAddFiles();
void slotAddPattern();
void slotRemoveEntries();
void slotEditEntry();
private:
void setupUI();
void setupUntrackedList();
private:
QListWidget *m_ignoreTable;
QListWidget *m_untrackedList;
KPushButton *m_addFiles;
KPushButton *m_addPattern;
KPushButton *m_removeEntries;
KPushButton *m_editEntry;
};
#endif /* HGCONFIG_IGNOREWIDGET_H */

View file

@ -0,0 +1,260 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "pathconfig.h"
#include "hgconfig.h"
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTableWidget>
#include <QtGui/QHeaderView>
#include <QtCore/QEvent>
#include <kpushbutton.h>
#include <kaction.h>
#include <klocale.h>
#include <kmenu.h>
#include <kmessagebox.h>
#include <kdebug.h>
HgPathConfigWidget::HgPathConfigWidget(QWidget *parent):
QWidget(parent),
m_loadingCell(false),
m_allValidData(true),
m_newAdd(false)
{
setupUI();
loadConfig();
}
void HgPathConfigWidget::setupContextMenu()
{
m_addAction = new KAction(this);
m_addAction->setIcon(KIcon("add"));
m_addAction->setText(i18nc("@action:inmenu",
"Add"));
connect(m_addAction, SIGNAL(triggered()), this, SLOT(slotAddPath()));
m_modifyAction = new KAction(this);
m_modifyAction->setIcon(KIcon("edit"));
m_modifyAction->setText(i18nc("@action:inmenu",
"Edit"));
connect(m_modifyAction, SIGNAL(triggered()), this, SLOT(slotModifyPath()));
m_deleteAction = new KAction(this);
m_deleteAction->setIcon(KIcon("remove"));
m_deleteAction->setText(i18nc("@action:inmenu",
"Remove"));
connect(m_deleteAction, SIGNAL(triggered()), this, SLOT(slotDeletePath()));
m_contextMenu = new KMenu(this);
m_contextMenu->addAction(m_addAction);
m_contextMenu->addAction(m_modifyAction);
m_contextMenu->addAction(m_deleteAction);
connect(m_pathsListWidget, SIGNAL(cellChanged(int, int)),
this, SLOT(slotCellChanged(int, int)));
connect(m_pathsListWidget, SIGNAL(itemSelectionChanged()),
this, SLOT(slotSelectionChanged()));
connect(m_pathsListWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
this, SLOT(slotContextMenuRequested(const QPoint&)));
}
void HgPathConfigWidget::setupUI()
{
// add, remove, modify buttons goes here
QHBoxLayout *actionsLayout = new QHBoxLayout;
m_addPathButton = new KPushButton(i18nc("@label:button", "Add"));
m_modifyPathButton = new KPushButton(i18nc("@label:button", "Edit"));
m_deletePathButton = new KPushButton(i18nc("@label:button", "Remove"));
actionsLayout->addWidget(m_addPathButton);
actionsLayout->addWidget(m_modifyPathButton);
actionsLayout->addWidget(m_deletePathButton);
connect(m_addPathButton, SIGNAL(clicked()), this, SLOT(slotAddPath()));
connect(m_modifyPathButton, SIGNAL(clicked()), this, SLOT(slotModifyPath()));
connect(m_deletePathButton, SIGNAL(clicked()), this, SLOT(slotDeletePath()));
/// create and setup the Table Widget
m_pathsListWidget = new QTableWidget;
setupContextMenu(); // make context menu
m_pathsListWidget->setColumnCount(2);
m_pathsListWidget->verticalHeader()->hide();
m_pathsListWidget->horizontalHeader()->hide();
m_pathsListWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
m_pathsListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
m_pathsListWidget->setEditTriggers(QAbstractItemView::DoubleClicked);
m_pathsListWidget->horizontalHeader()->setStretchLastSection(true);
m_pathsListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
// setup main layout
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(actionsLayout);
mainLayout->addWidget(m_pathsListWidget);
setLayout(mainLayout);
}
void HgPathConfigWidget::loadConfig()
{
HgConfig hgc(HgConfig::RepoConfig);
m_remotePathMap = hgc.repoRemotePathList();
m_loadingCell = true;
m_pathsListWidget->clearContents();
m_removeList.clear();
QMutableMapIterator<QString, QString> it(m_remotePathMap);
int count = 0;
while (it.hasNext()) {
it.next();
QTableWidgetItem *alias = new QTableWidgetItem;
QTableWidgetItem *path = new QTableWidgetItem;
alias->setText(it.key());
path->setText(it.value());
m_pathsListWidget->insertRow(count);
m_pathsListWidget->setItem(count, 0, alias);
m_pathsListWidget->setItem(count, 1, path);
}
m_pathsListWidget->resizeRowsToContents();
m_loadingCell = false;
}
void HgPathConfigWidget::saveConfig()
{
HgConfig hgc(HgConfig::RepoConfig);
if (!m_allValidData) {
return;
}
// first delete the alias in remove list from hgrc
foreach(QString alias, m_removeList) {
hgc.deleteRepoRemotePath(alias);
}
// now save the new map in table to hgrc
QMutableMapIterator<QString, QString> it(m_remotePathMap);
while (it.hasNext()) {
it.next();
QString alias = it.key();
QString url = it.value();
hgc.setRepoRemotePath(alias, url);
}
}
void HgPathConfigWidget::slotContextMenuRequested(const QPoint &pos)
{
if (m_pathsListWidget->indexAt(pos).isValid()) {
m_deleteAction->setEnabled(true);
m_modifyAction->setEnabled(true);
} else {
m_deleteAction->setEnabled(false);
m_modifyAction->setEnabled(false);
}
m_addAction->setEnabled(true);
m_contextMenu->exec(m_pathsListWidget->mapToGlobal(pos));
}
void HgPathConfigWidget::slotAddPath()
{
QTableWidgetItem *alias = new QTableWidgetItem;
QTableWidgetItem *path = new QTableWidgetItem;
int count = m_pathsListWidget->rowCount();
m_loadingCell = true;
m_pathsListWidget->insertRow(count);
m_pathsListWidget->setItem(count, 0, alias);
m_pathsListWidget->setItem(count, 1, path);
m_pathsListWidget->resizeRowsToContents();
m_pathsListWidget->setCurrentItem(alias);
m_pathsListWidget->editItem(m_pathsListWidget->item(count, 0));
m_loadingCell = false;
m_newAdd = true;
}
void HgPathConfigWidget::slotDeletePath()
{
int currentRow = m_pathsListWidget->currentRow();
m_removeList << m_pathsListWidget->item(currentRow, 0)->text();
m_remotePathMap.remove(m_pathsListWidget->item(currentRow, 0)->text());
m_pathsListWidget->removeRow(currentRow);
}
void HgPathConfigWidget::slotModifyPath()
{
m_pathsListWidget->editItem(m_pathsListWidget->currentItem());
}
void HgPathConfigWidget::slotCellChanged(int row, int col)
{
if (m_loadingCell ||
m_oldSelValue == m_pathsListWidget->currentItem()->text()) {
return;
}
QTableWidgetItem *alias = m_pathsListWidget->item(row, 0);
QTableWidgetItem *url = m_pathsListWidget->item(row, 1);
if (alias->text().isEmpty() || url->text().isEmpty()) {
alias->setBackground(Qt::red);
url->setBackground(Qt::red);
m_allValidData = false;
return;
}
else if (m_remotePathMap.contains(alias->text()) && m_newAdd) {
m_oldSelValue = m_pathsListWidget->currentItem()->text();
alias->setBackground(Qt::red);
url->setBackground(Qt::red);
m_allValidData = false;
return;
}
else if (m_remotePathMap.contains(alias->text()) && col == 0) {
m_oldSelValue = m_pathsListWidget->currentItem()->text();
alias->setBackground(Qt::red);
url->setBackground(Qt::red);
m_allValidData = false;
return;
}
else {
kDebug() << "bingo";
if (!m_newAdd && col == 0) {
m_remotePathMap.remove(m_oldSelValue);
m_removeList << m_oldSelValue;
}
m_remotePathMap.insert(alias->text(), url->text());
m_oldSelValue = m_pathsListWidget->currentItem()->text();
alias->setBackground(Qt::NoBrush);
url->setBackground(Qt::NoBrush);
m_allValidData = true;
}
m_newAdd = false;
}
void HgPathConfigWidget::slotSelectionChanged()
{
m_oldSelValue = m_pathsListWidget->currentItem()->text();
}
#include "moc_pathconfig.cpp"

View file

@ -0,0 +1,90 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGPATH_CONFIG_H
#define HGPATH_CONFIG_H
#include <QtGui/QWidget>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QTableWidget>
#include <QTableWidgetItem>
class KPushButton;
class KAction;
class KMenu;
/**
* UI to add, remove and modify paths in repository's hgrc file. Can be used with
* repository hgrc file only.
*/
class HgPathConfigWidget : public QWidget
{
Q_OBJECT
public:
HgPathConfigWidget(QWidget *parent = 0);
public slots:
void saveConfig();
void loadConfig();
private:
void setupUI();
/**
* Prepare context menu and its actions for table widget showing path.
*/
void setupContextMenu();
private slots:
/**
* Show context menu and changed enabled status of actions according
* to the position where menu is requested.
*/
void slotContextMenuRequested(const QPoint &pos);
void slotCellChanged(int row, int col);
void slotSelectionChanged();
void slotAddPath();
void slotModifyPath();
void slotDeletePath();
private:
QTableWidget *m_pathsListWidget;
bool m_loadingCell;
bool m_allValidData;
bool m_newAdd;
QString m_oldSelValue;
KPushButton *m_addPathButton;
KPushButton *m_deletePathButton;
KPushButton *m_modifyPathButton;
KAction *m_addAction;
KAction *m_modifyAction;
KAction *m_deleteAction;
KMenu *m_contextMenu;
QMap<QString, QString> m_remotePathMap;
QStringList m_removeList;
};
#endif // HGPATH_CONFIG_H

View file

@ -0,0 +1,91 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "pluginsettings.h"
#include "hgconfig.h"
#include <QtCore/QDir>
#include <QtGui/QLabel>
#include <QtGui/QGridLayout>
#include <klineedit.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <kdebug.h>
#include <kurl.h>
#include <kpushbutton.h>
HgPluginSettingsWidget::HgPluginSettingsWidget(QWidget *parent) :
QWidget(parent),
m_config(0)
{
setupUI();
loadConfig();
connect(m_diffBrowseButton, SIGNAL(clicked()),
this, SLOT(browse_diff()));
}
void HgPluginSettingsWidget::saveConfig()
{
KConfigGroup group(m_config, QLatin1String("diff"));
group.writeEntry(QLatin1String("exec"), m_diffProg->text());
group.config()->sync();
}
void HgPluginSettingsWidget::loadConfig()
{
KUrl url = KUrl::fromPath(QDir::homePath());
url.addPath(".dolphin-hg");
m_config = new KConfig(url.path(), KConfig::SimpleConfig);
KConfigGroup group(m_config, QLatin1String("diff"));
QString diffExec = group.readEntry(QLatin1String("exec"), QString()).trimmed();
m_diffProg->setText(diffExec);
}
void HgPluginSettingsWidget::setupUI()
{
m_diffProg = new KLineEdit;
m_diffBrowseButton = new KPushButton(i18nc("@label", "Browse"));
QLabel *diffProgLabel = new QLabel(i18nc("@label",
"Visual Diff Executable"));
QGridLayout *layout = new QGridLayout;
layout->addWidget(diffProgLabel, 0, 0);
layout->addWidget(m_diffProg, 0, 1);
layout->addWidget(m_diffBrowseButton, 0, 2);
layout->setRowStretch(layout->rowCount(), 1);
setLayout(layout);
}
void HgPluginSettingsWidget::browse_diff()
{
QString path = KFileDialog::getOpenFileName();
if (path.isEmpty()) {
return;
}
m_diffProg->setText(path);
}
#include "moc_pluginsettings.cpp"

View file

@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HG_PLUGIN_SETTINGS_WIDGET_H
#define HG_PLUGIN_SETTINGS_WIDGET_H
#include <QtGui/QWidget>
#include "hgconfig.h"
class KLineEdit;
class KConfig;
class KPushButton;
/**
* Plugin Specific settings. Not those supposed to be saved in
* .hgrc file, but in $HOME/.dolphin-hg
*/
class HgPluginSettingsWidget : public QWidget
{
Q_OBJECT
public:
HgPluginSettingsWidget(QWidget *parent = 0);
public slots:
void saveConfig();
void loadConfig();
private slots:
void browse_diff();
private:
void setupUI();
private:
KLineEdit *m_diffProg;
KConfig *m_config;
KPushButton *m_diffBrowseButton;
};
#endif // HG_PLUGIN_SETTINGS_WIDGET_H

View file

@ -0,0 +1,114 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "configdialog.h"
#include "hgwrapper.h"
#include "fileviewhgpluginsettings.h"
#include "config-widgets/generalconfig.h"
#include "config-widgets/pathconfig.h"
#include "config-widgets/ignorewidget.h"
#include "config-widgets/pluginsettings.h"
#include <QtGui/QWidget>
#include <klocale.h>
#include <kdebug.h>
HgConfigDialog::HgConfigDialog(HgConfig::ConfigType type, QWidget *parent):
KPageDialog(parent, Qt::Dialog),
m_configType(type)
{
// dialog properties
if (m_configType == HgConfig::RepoConfig) {
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Repository Configuration"));
} else {
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Global Configuration"));
}
this->setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
//this->enableButtonOk(false);
setupUI();
loadGeometry();
connect(this, SIGNAL(applyClicked()), this, SLOT(saveSettings()));
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
}
void HgConfigDialog::setupUI()
{
m_generalConfig = new HgGeneralConfigWidget(m_configType);
addPage(m_generalConfig, i18nc("@label:group", "General Settings"));
if (m_configType == HgConfig::RepoConfig) {
m_pathConfig = new HgPathConfigWidget;
addPage(m_pathConfig, i18nc("@label:group", "Repository Paths"));
m_ignoreWidget = new HgIgnoreWidget;
addPage(m_ignoreWidget, i18nc("@label:group", "Ignored Files"));
}
else if (m_configType == HgConfig::GlobalConfig) {
m_pluginSetting = new HgPluginSettingsWidget;
addPage(m_pluginSetting, i18nc("@label:group", "Plugin Settings"));
}
}
void HgConfigDialog::saveSettings()
{
kDebug() << "Saving Mercurial configuration";
m_generalConfig->saveConfig();
if (m_configType == HgConfig::RepoConfig) {
m_pathConfig->saveConfig();
m_ignoreWidget->saveConfig();
}
else if (m_configType == HgConfig::GlobalConfig) {
m_pluginSetting->saveConfig();
}
}
void HgConfigDialog::done(int r)
{
if (r == KDialog::Accepted) {
saveSettings();
KDialog::done(r);
}
else {
KDialog::done(r);
}
}
void HgConfigDialog::loadGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->configDialogWidth(),
settings->configDialogHeight()));
}
void HgConfigDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setConfigDialogHeight(this->height());
settings->setConfigDialogWidth(this->width());
settings->writeConfig();
}
#include "moc_configdialog.cpp"

View file

@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCONFIGDILAOG_H
#define HGCONFIGDILAOG_H
#include "hgconfig.h"
#include <kpagedialog.h>
class HgGeneralConfigWidget;
class HgPathConfigWidget;
class HgIgnoreWidget;
class HgPluginSettingsWidget;
/**
* Implemets a dialog which provides an easy way to edit several
* configuration options for Mercurial and the plugin.
*/
class HgConfigDialog : public KPageDialog
{
Q_OBJECT
public:
HgConfigDialog(HgConfig::ConfigType type, QWidget *parent = 0);
private:
void done(int r);
// user interface
void setupUI();
private slots:
void saveSettings();
void saveGeometry();
void loadGeometry();
private:
HgGeneralConfigWidget *m_generalConfig;
HgPathConfigWidget *m_pathConfig;
HgIgnoreWidget *m_ignoreWidget;
HgPluginSettingsWidget *m_pluginSetting;
HgConfig::ConfigType m_configType;
};
#endif // HGCONFIGDILAOG_H

View file

@ -0,0 +1,87 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "createdialog.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QHBoxLayout>
#include <QtCore/QProcess>
#include <QtGui/QFrame>
#include <QtGui/QLabel>
#include <klocale.h>
#include <klineedit.h>
#include <kmessagebox.h>
HgCreateDialog::HgCreateDialog(const QString &directory, QWidget *parent):
KDialog(parent, Qt::Dialog),
m_workingDirectory(directory)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Initialize Repository"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Initialize Repository"));
//this->enableButtonOk(false);
//////////////
// Setup UI //
//////////////
m_directory = new QLabel("<b>" + m_workingDirectory + "</b>");
m_repoNameEdit = new KLineEdit;
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(m_directory);
mainLayout->addWidget(m_repoNameEdit);
QFrame *frame = new QFrame;
frame->setLayout(mainLayout);
setMainWidget(frame);
m_repoNameEdit->setFocus();
}
void HgCreateDialog::done(int r)
{
if (r == KDialog::Accepted) {
QProcess process;
QStringList args;
args << QLatin1String("init");
if (!m_repoNameEdit->text().isEmpty()) {
args << m_repoNameEdit->text();
}
process.setWorkingDirectory(m_workingDirectory);
process.start(QLatin1String("hg"), args);
process.waitForFinished();
if (process.exitCode() == 0 && process.exitStatus() == QProcess::NormalExit) {
KDialog::done(r);
}
else {
KMessageBox::error(this, i18nc("error message", "Error creating repository!"));
}
}
else {
KDialog::done(r);
}
}
#include "moc_createdialog.cpp"

View file

@ -0,0 +1,51 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCREATEDILAOG_H
#define HGCREATEDILAOG_H
#include <QtCore/QString>
#include <kdialog.h>
class KLineEdit;
#include <QLabel>
/**
* Dialog to initialize new mercurial repository
*/
class HgCreateDialog : public KDialog
{
Q_OBJECT
public:
HgCreateDialog(const QString &directory, QWidget *parent = 0);
private:
void done(int r);
void setWorkingDirectory(const QString &directory);
private:
QString m_workingDirectory;
KLineEdit *m_repoNameEdit;
QLabel *m_directory;
};
#endif // HGCREATEDILAOG_H

View file

@ -0,0 +1,190 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "exportdialog.h"
#include "fileviewhgpluginsettings.h"
#include "commitinfowidget.h"
#include "hgwrapper.h"
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QListWidget>
#include <QtCore/QProcess>
#include <QtCore/QTextCodec>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
HgExportDialog::HgExportDialog(QWidget *parent) :
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Export"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Export"));
//
setupUI();
loadCommits();
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->exportDialogWidth(),
settings->exportDialogHeight()));
//
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
}
void HgExportDialog::setupUI()
{
QGroupBox *mainGroup = new QGroupBox;
QGridLayout *mainLayout = new QGridLayout;
m_commitInfoWidget = new HgCommitInfoWidget;
m_commitInfoWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
mainLayout->addWidget(m_commitInfoWidget);
mainGroup->setLayout(mainLayout);
// options
m_optionGroup = new QGroupBox(i18nc("@label:group", "Options"));
m_optText = new QCheckBox(i18nc("@label", "Treat all files as text"));
m_optGit = new QCheckBox(i18nc("@label", "Use Git extended diff format"));
m_optNoDates = new QCheckBox(i18nc("@label", "Omit dates from diff headers"));
QVBoxLayout *optionLayout = new QVBoxLayout;
optionLayout->addWidget(m_optText);
optionLayout->addWidget(m_optGit);
optionLayout->addWidget(m_optNoDates);
m_optionGroup->setLayout(optionLayout);
//setup main dialog widget
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(mainGroup);
layout->addWidget(m_optionGroup);
widget->setLayout(layout);
setMainWidget(widget);
}
void HgExportDialog::loadCommits()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update heads list
QProcess process;
process.setWorkingDirectory(hgWrapper->getBaseDir());
QStringList args;
args << QLatin1String("log");
args << QLatin1String("--template");
args << QLatin1String("{rev}\n{node|short}\n{branch}\n"
"{author}\n{desc|firstline}\n");
process.start(QLatin1String("hg"), args);
process.waitForFinished();
m_commitInfoWidget->clear();
const int FINAL = 5;
char buffer[FINAL][1024];
int count = 0;
while (process.readLine(buffer[count], sizeof(buffer[count])) > 0) {
if (count == FINAL - 1) {
QString rev = QTextCodec::codecForLocale()->toUnicode(buffer[0]).trimmed();
QString changeset = QTextCodec::codecForLocale()->toUnicode(buffer[1]).trimmed();
QString branch = QTextCodec::codecForLocale()->toUnicode(buffer[2]).trimmed();
QString author = QTextCodec::codecForLocale()->toUnicode(buffer[3]).trimmed();
QString log = QTextCodec::codecForLocale()->toUnicode(buffer[4]).trimmed();
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, rev);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitInfoWidget->addItem(item);
}
count = (count + 1)%FINAL;
}
}
void HgExportDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setExportDialogHeight(this->height());
settings->setExportDialogWidth(this->width());
settings->writeConfig();
}
void HgExportDialog::done(int r)
{
if (r == KDialog::Accepted) {
QList<QListWidgetItem*> items = m_commitInfoWidget->selectedItems();
if (items.empty()) {
KMessageBox::error(this, i18nc("@message:error",
"Please select at least one changeset to be exported!"));
return;
}
QStringList args;
if (m_optText->checkState() == Qt::Checked) {
args << QLatin1String("--text");
}
if (m_optGit->checkState() == Qt::Checked) {
args << QLatin1String("--git");
}
if (m_optNoDates->checkState() == Qt::Checked) {
args << QLatin1String("--nodates");
}
args << QLatin1String("-r");
foreach (QListWidgetItem *item, items) {
args << item->data(Qt::DisplayRole).toString();
}
QString directory = KFileDialog::getExistingDirectory();
if (directory.isEmpty()) {
return;
}
if (!directory.endsWith('/')) {
directory.append('/');
}
args << QLatin1String("--output");
args << directory + QLatin1String("%b_%h.patch");
HgWrapper *hgw = HgWrapper::instance();
if (hgw->executeCommandTillFinished(QLatin1String("export"), args)) {
KDialog::done(r);
}
else {
KMessageBox::error(this, hgw->readAllStandardError());
}
}
else {
KDialog::done(r);
}
}
#include "moc_exportdialog.cpp"

View file

@ -0,0 +1,66 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGEXPORTDIALOG_H
#define HGEXPORTDIALOG_H
#include <kdialog.h>
class HgCommitInfoWidget;
#include <QCheckBox>
#include <QGroupBox>
class KLineEdit;
//TODO: Some helper for writing patterns
//
/**
* Dialog to implment mercurial export feature. Dialogs presents list of
* changesets from which the user will select entries and export a series of
* patch files for each changeset.
*/
class HgExportDialog : public KDialog
{
Q_OBJECT
public:
HgExportDialog(QWidget *parent=0);
public slots:
void done(int r);
private slots:
void saveGeometry();
private:
void setupUI();
void loadCommits();
private:
HgCommitInfoWidget *m_commitInfoWidget;
//options
QGroupBox *m_optionGroup;
QCheckBox *m_optText;
QCheckBox *m_optGit;
QCheckBox *m_optNoDates;
};
#endif /* HGEXPORTDIALOG_H */

View file

@ -0,0 +1,841 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "fileviewhgplugin.h"
#include "hgconfig.h"
#include "configdialog.h"
#include "renamedialog.h"
#include "commitdialog.h"
#include "branchdialog.h"
#include "tagdialog.h"
#include "updatedialog.h"
#include "clonedialog.h"
#include "createdialog.h"
#include "pushdialog.h"
#include "pulldialog.h"
#include "mergedialog.h"
#include "bundledialog.h"
#include "exportdialog.h"
#include "importdialog.h"
#include "servedialog.h"
#include "backoutdialog.h"
#include <QtCore/QTextCodec>
#include <QtCore/QDir>
#include <kaction.h>
#include <kmenu.h>
#include <kicon.h>
#include <klocale.h>
#include <kdebug.h>
#include <kurl.h>
#include <kmessagebox.h>
#include <kfiledialog.h>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kservice.h>
#include <kmimetypetrader.h>
#include <KPluginFactory>
#include <KPluginLoader>
K_PLUGIN_FACTORY(FileViewHgPluginFactory, registerPlugin<FileViewHgPlugin>();)
K_EXPORT_PLUGIN(FileViewHgPluginFactory("fileviewhgplugin"))
//TODO: Build a proper status signal system to sync HgWrapper/Dialgs with this
//TODO: Show error messages and set their message approproately(hg output)
//TODO: Use i18nc rather thn i18c throughout plugin
FileViewHgPlugin::FileViewHgPlugin(QObject *parent, const QList<QVariant> &args):
KVersionControlPlugin(parent),
m_mainContextMenu(0),
m_addAction(0),
m_removeAction(0),
m_renameAction(0),
m_commitAction(0),
m_branchAction(0),
m_tagAction(0),
m_updateAction(0),
m_cloneAction(0),
m_createAction(0),
m_globalConfigAction(0),
m_repoConfigAction(0),
m_pushAction(0),
m_pullAction(0),
m_revertAction(0),
m_revertAllAction(0),
m_rollbackAction(0),
m_mergeAction(0),
m_bundleAction(0),
m_exportAction(0),
m_unbundleAction(0),
m_importAction(0),
m_diffAction(0),
m_serveAction(0),
m_backoutAction(0),
m_hgWrapper(0),
m_retrievalHgw(0)
{
Q_UNUSED(args);
m_addAction = new KAction(this);
m_addAction->setIcon(KIcon("list-add"));
m_addAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Add"));
connect(m_addAction, SIGNAL(triggered()),
this, SLOT(addFiles()));
m_removeAction = new KAction(this);
m_removeAction->setIcon(KIcon("list-remove"));
m_removeAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Remove"));
connect(m_removeAction, SIGNAL(triggered()),
this, SLOT(removeFiles()));
m_renameAction = new KAction(this);
m_renameAction->setIcon(KIcon("list-rename"));
m_renameAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Rename"));
connect(m_renameAction, SIGNAL(triggered()),
this, SLOT(renameFile()));
m_commitAction = new KAction(this);
m_commitAction->setIcon(KIcon("svn-commit"));
m_commitAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Commit"));
connect(m_commitAction, SIGNAL(triggered()),
this, SLOT(commit()));
m_tagAction = new KAction(this);
m_tagAction->setIcon(KIcon("bookmark-new"));
m_tagAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Tag"));
connect(m_tagAction, SIGNAL(triggered()),
this, SLOT(tag()));
m_branchAction = new KAction(this);
m_branchAction->setIcon(KIcon("bookmark-new"));
m_branchAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Branch"));
connect(m_branchAction, SIGNAL(triggered()),
this, SLOT(branch()));
m_cloneAction = new KAction(this);
m_cloneAction->setIcon(KIcon("hg-clone"));
m_cloneAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Clone"));
connect(m_cloneAction, SIGNAL(triggered()),
this, SLOT(clone()));
m_createAction = new KAction(this);
m_createAction->setIcon(KIcon("hg-create"));
m_createAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Init"));
connect(m_createAction, SIGNAL(triggered()),
this, SLOT(create()));
m_updateAction = new KAction(this);
m_updateAction->setIcon(KIcon("svn-update"));
m_updateAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Update"));
connect(m_updateAction, SIGNAL(triggered()),
this, SLOT(update()));
m_globalConfigAction = new KAction(this);
m_globalConfigAction->setIcon(KIcon("hg-config"));
m_globalConfigAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Global Config"));
connect(m_globalConfigAction, SIGNAL(triggered()),
this, SLOT(global_config()));
m_repoConfigAction = new KAction(this);
m_repoConfigAction->setIcon(KIcon("hg-config"));
m_repoConfigAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Repository Config"));
connect(m_repoConfigAction, SIGNAL(triggered()),
this, SLOT(repo_config()));
m_pushAction = new KAction(this);
m_pushAction->setIcon(KIcon("git-push"));
m_pushAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Push"));
connect(m_pushAction, SIGNAL(triggered()),
this, SLOT(push()));
m_pullAction = new KAction(this);
m_pullAction->setIcon(KIcon("git-pull"));
m_pullAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Pull"));
connect(m_pullAction, SIGNAL(triggered()),
this, SLOT(pull()));
m_revertAction = new KAction(this);
m_revertAction->setIcon(KIcon("hg-revert"));
m_revertAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Revert"));
connect(m_revertAction, SIGNAL(triggered()),
this, SLOT(revert()));
m_revertAllAction = new KAction(this);
m_revertAllAction->setIcon(KIcon("hg-revert"));
m_revertAllAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Revert All"));
connect(m_revertAllAction, SIGNAL(triggered()),
this, SLOT(revertAll()));
m_rollbackAction = new KAction(this);
m_rollbackAction->setIcon(KIcon("hg-rollback"));
m_rollbackAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Rollback"));
connect(m_rollbackAction, SIGNAL(triggered()),
this, SLOT(rollback()));
m_mergeAction = new KAction(this);
m_mergeAction->setIcon(KIcon("hg-merge"));
m_mergeAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Merge"));
connect(m_mergeAction, SIGNAL(triggered()),
this, SLOT(merge()));
m_bundleAction = new KAction(this);
m_bundleAction->setIcon(KIcon("hg-bundle"));
m_bundleAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Bundle"));
connect(m_bundleAction, SIGNAL(triggered()),
this, SLOT(bundle()));
m_exportAction = new KAction(this);
m_exportAction->setIcon(KIcon("hg-export"));
m_exportAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Export"));
connect(m_exportAction, SIGNAL(triggered()),
this, SLOT(exportChangesets()));
m_importAction = new KAction(this);
m_importAction->setIcon(KIcon("hg-import"));
m_importAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Import"));
connect(m_importAction, SIGNAL(triggered()),
this, SLOT(importChangesets()));
m_unbundleAction = new KAction(this);
m_unbundleAction->setIcon(KIcon("hg-unbundle"));
m_unbundleAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Unbundle"));
connect(m_unbundleAction, SIGNAL(triggered()),
this, SLOT(unbundle()));
m_serveAction = new KAction(this);
m_serveAction->setIcon(KIcon("hg-serve"));
m_serveAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Serve"));
connect(m_serveAction, SIGNAL(triggered()),
this, SLOT(serve()));
m_backoutAction = new KAction(this);
m_backoutAction->setIcon(KIcon("hg-backout"));
m_backoutAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Backout"));
connect(m_backoutAction, SIGNAL(triggered()),
this, SLOT(backout()));
m_diffAction = new KAction(this);
m_diffAction->setIcon(KIcon("hg-diff"));
m_diffAction->setText(i18nc("@action:inmenu",
"<application>Hg</application> Diff"));
connect(m_diffAction, SIGNAL(triggered()),
this, SLOT(diff()));
/* Submenu to make the main menu less cluttered */
m_mainContextMenu = new KMenu;
m_mainContextMenu->addAction(m_updateAction);
m_mainContextMenu->addAction(m_branchAction);
m_mainContextMenu->addAction(m_tagAction);
m_mainContextMenu->addAction(m_mergeAction);
m_mainContextMenu->addAction(m_revertAllAction);
m_mainContextMenu->addAction(m_rollbackAction);
m_mainContextMenu->addAction(m_backoutAction);
m_mainContextMenu->addAction(m_bundleAction);
m_mainContextMenu->addAction(m_unbundleAction);
m_mainContextMenu->addAction(m_exportAction);
m_mainContextMenu->addAction(m_importAction);
m_mainContextMenu->addAction(m_serveAction);
m_mainContextMenu->addAction(m_globalConfigAction);
m_mainContextMenu->addAction(m_repoConfigAction);
m_menuAction = new KAction(this);
m_menuAction->setIcon(KIcon("hg-main"));
m_menuAction->setText(i18nc("@action:inmenu",
"<application>Mercurial</application>"));
m_menuAction->setMenu(m_mainContextMenu);
}
FileViewHgPlugin::~FileViewHgPlugin()
{
}
void FileViewHgPlugin::createHgWrapper() const
{
static bool created = false;
if (created && m_hgWrapper != 0) {
return;
}
created = true;
m_hgWrapper = HgWrapper::instance();
connect(m_hgWrapper,
SIGNAL(primaryOperationFinished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));
connect(m_hgWrapper, SIGNAL(primaryOperationError(QProcess::ProcessError)),
this, SLOT(slotOperationError()));
}
QString FileViewHgPlugin::fileName() const
{
return QLatin1String(".hg");
}
bool FileViewHgPlugin::beginRetrieval(const QString &directory)
{
clearMessages();
m_currentDir = directory;
m_versionInfoHash.clear();
//createHgWrapper();
//m_hgWrapper->setCurrentDir(directory);
//m_hgWrapper->getItemVersions(m_versionInfoHash);
if (m_retrievalHgw == 0) {
m_retrievalHgw = new HgWrapper;
}
m_retrievalHgw->setCurrentDir(directory);
m_retrievalHgw->getItemVersions(m_versionInfoHash);
return true;
}
void FileViewHgPlugin::endRetrieval()
{
}
KVersionControlPlugin::ItemVersion FileViewHgPlugin::itemVersion(const KFileItem &item) const
{
//FIXME: When folder is empty or all files within untracked.
const QString itemUrl = item.localPath();
if (item.isDir()) {
QHash<QString, ItemVersion>::const_iterator it
= m_versionInfoHash.constBegin();
while (it != m_versionInfoHash.constEnd()) {
if (it.key().startsWith(itemUrl)) {
const ItemVersion state = m_versionInfoHash.value(it.key());
if (state == LocallyModifiedVersion ||
state == AddedVersion ||
state == RemovedVersion) {
return LocallyModifiedVersion;
}
}
++it;
}
// Making folders with all files within untracked 'Unversioned'
// will disable the context menu there. Will enable recursive
// add however.
QDir dir(item.localPath());
QStringList filesInside = dir.entryList();
foreach (const QString &fileName, filesInside) {
if (fileName == "." || fileName == ".." ) {
continue;
}
KUrl tempUrl(dir.absoluteFilePath(fileName));
KFileItem tempFileItem(KFileItem::Unknown,
KFileItem::Unknown, tempUrl);
if (itemVersion(tempFileItem) == NormalVersion) {
return NormalVersion;
}
}
return UnversionedVersion;
}
if (m_versionInfoHash.contains(itemUrl)) {
return m_versionInfoHash.value(itemUrl);
}
return NormalVersion;
}
QList<QAction*> FileViewHgPlugin::actions(const KFileItemList &items) const
{
//TODO: Make it work with universal context menu when imlpemented
// in dolphin
kDebug() << items.count();
if (items.count() == 1 && items.first().isDir()) {
return directoryContextMenu(m_currentDir);
}
else {
return itemContextMenu(items);
}
return QList<QAction*>();
}
QList<QAction*> FileViewHgPlugin::universalContextMenuActions(const QString &directory) const
{
QList<QAction*> result;
m_universalCurrentDirectory = directory;
result.append(m_createAction);
result.append(m_cloneAction);
return result;
}
QList<QAction*> FileViewHgPlugin::itemContextMenu(const KFileItemList &items) const
{
Q_ASSERT(!items.isEmpty());
clearMessages();
createHgWrapper();
m_hgWrapper->setCurrentDir(m_currentDir);
if (!m_hgWrapper->isBusy()) {
m_contextItems.clear();
foreach (const KFileItem &item, items) {
m_contextItems.append(item);
}
//see which actions should be enabled
int versionedCount = 0;
int addableCount = 0;
int revertableCount = 0;
foreach (const KFileItem &item, items) {
const ItemVersion state = itemVersion(item);
if (state != UnversionedVersion && state != RemovedVersion) {
++versionedCount;
}
if (state == UnversionedVersion ||
state == LocallyModifiedUnstagedVersion) {
++addableCount;
}
if (state == LocallyModifiedVersion ||
state == AddedVersion ||
state == RemovedVersion) {
++revertableCount;
}
}
m_addAction->setEnabled(addableCount == items.count());
m_removeAction->setEnabled(versionedCount == items.count());
m_revertAction->setEnabled(revertableCount == items.count());
m_diffAction->setEnabled(revertableCount == items.count() &&
items.size() == 1);
m_renameAction->setEnabled(items.size() == 1 &&
itemVersion(items.first()) != UnversionedVersion);
}
else {
m_addAction->setEnabled(false);
m_removeAction->setEnabled(false);
m_renameAction->setEnabled(false);
m_revertAction->setEnabled(false);
m_diffAction->setEnabled(false);
}
QList<QAction*> actions;
actions.append(m_addAction);
actions.append(m_removeAction);
actions.append(m_renameAction);
actions.append(m_revertAction);
actions.append(m_diffAction);
return actions;
}
QList<QAction*> FileViewHgPlugin::directoryContextMenu(const QString &directory) const
{
QList<QAction*> actions;
clearMessages();
createHgWrapper();
m_hgWrapper->setCurrentDir(directory);
if (!m_hgWrapper->isBusy()) {
actions.append(m_commitAction);
}
actions.append(m_pushAction);
actions.append(m_pullAction);
actions.append(m_diffAction);
actions.append(m_menuAction);
return actions;
}
void FileViewHgPlugin::addFiles()
{
Q_ASSERT(!m_contextItems.isEmpty());
QString infoMsg = i18nc("@info:status",
"Adding files to <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Adding files to <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Added files to <application>Hg</application> repository.");
emit infoMessage(infoMsg);
m_hgWrapper->addFiles(m_contextItems);
}
void FileViewHgPlugin::removeFiles()
{
Q_ASSERT(!m_contextItems.isEmpty());
int answer = KMessageBox::questionYesNo(0, i18nc("@message:yesorno",
"Would you like to remove selected files "
"from the repository?"));
if (answer == KMessageBox::No) {
return;
}
QString infoMsg = i18nc("@info:status",
"Removing files from <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Removing files from <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Removed files from <application>Hg</application> repository.");
emit infoMessage(infoMsg);
m_hgWrapper->removeFiles(m_contextItems);
}
void FileViewHgPlugin::renameFile()
{
Q_ASSERT(m_contextItems.size() == 1);
m_errorMsg = i18nc("@info:status",
"Renaming of file in <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Renamed file in <application>Hg</application> repository successfully.");
emit infoMessage(i18nc("@info:status",
"Renaming file in <application>Hg</application> repository."));
HgRenameDialog dialog(m_contextItems.first());
dialog.exec();
m_contextItems.clear();
}
void FileViewHgPlugin::commit()
{
if (m_hgWrapper->isWorkingDirectoryClean()) {
KMessageBox::information(0, i18nc("@message", "No changes for commit!"));
return;
}
//FIXME: Disable emitting of status messages when executing sub tasks.
m_errorMsg = i18nc("@info:status",
"Commit to <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Committed to <application>Hg</application> repository.");
emit infoMessage(i18nc("@info:status",
"Commit <application>Hg</application> repository."));
HgCommitDialog dialog;
if (dialog.exec() == QDialog::Accepted) {
emit itemVersionsChanged();
};
}
void FileViewHgPlugin::tag()
{
m_errorMsg = i18nc("@info:status",
"Tag operation in <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Tagging operation in <application>Hg</application> repository is successful.");
emit infoMessage(i18nc("@info:status",
"Tagging operation in <application>Hg</application> repository."));
HgTagDialog dialog;
dialog.exec();
}
void FileViewHgPlugin::update()
{
m_errorMsg = i18nc("@info:status",
"Update of <application>Hg</application> working directory failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Update of <application>Hg</application> working directory is successful.");
emit infoMessage(i18nc("@info:status",
"Updating <application>Hg</application> working directory."));
HgUpdateDialog dialog;
dialog.exec();
}
void FileViewHgPlugin::branch()
{
m_errorMsg = i18nc("@info:status",
"Branch operation on <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Branch operation on <application>Hg</application> repository completed successfully.");
emit infoMessage(i18nc("@info:status",
"Branch operation on <application>Hg</application> repository."));
HgBranchDialog dialog;
dialog.exec();
}
void FileViewHgPlugin::clone()
{
clearMessages();
HgCloneDialog dialog(m_universalCurrentDirectory);
dialog.exec();
}
void FileViewHgPlugin::create()
{
clearMessages();
HgCreateDialog dialog(m_universalCurrentDirectory);
dialog.exec();
}
void FileViewHgPlugin::global_config()
{
clearMessages();
HgConfigDialog diag(HgConfig::GlobalConfig);
diag.exec();
}
void FileViewHgPlugin::repo_config()
{
clearMessages();
HgConfigDialog diag(HgConfig::RepoConfig);
diag.exec();
}
void FileViewHgPlugin::push()
{
clearMessages();
HgPushDialog diag;
diag.exec();
}
void FileViewHgPlugin::pull()
{
clearMessages();
HgPullDialog diag;
diag.exec();
}
void FileViewHgPlugin::merge()
{
clearMessages();
HgMergeDialog diag;
diag.exec();
}
void FileViewHgPlugin::bundle()
{
clearMessages();
HgBundleDialog diag;
diag.exec();
}
void FileViewHgPlugin::unbundle()
{
clearMessages();
QString bundle = KFileDialog::getOpenFileName();
if (bundle.isEmpty()) {
return;
}
QStringList args;
args << bundle;
if (m_hgWrapper->executeCommandTillFinished(QLatin1String("unbundle"), args)) {
}
else {
KMessageBox::error(0, m_hgWrapper->readAllStandardError());
}
}
void FileViewHgPlugin::importChangesets()
{
clearMessages();
HgImportDialog diag;
diag.exec();
}
void FileViewHgPlugin::exportChangesets()
{
clearMessages();
HgExportDialog diag;
diag.exec();
}
void FileViewHgPlugin::revert()
{
clearMessages();
int answer = KMessageBox::questionYesNo(0, i18nc("@message:yesorno",
"Would you like to revert changes "
"made to selected files?"));
if (answer == KMessageBox::No) {
return;
}
QString infoMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository completed successfully.");
emit infoMessage(infoMsg);
m_hgWrapper->revert(m_contextItems);
}
void FileViewHgPlugin::revertAll()
{
int answer = KMessageBox::questionYesNo(0, i18nc("@message:yesorno",
"Would you like to revert all changes "
"made to current working directory?"));
if (answer == KMessageBox::No) {
return;
}
QString infoMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Reverting files in <application>Hg</application> repository completed successfully.");
emit infoMessage(infoMsg);
m_hgWrapper->revertAll();
}
void FileViewHgPlugin::diff()
{
QString infoMsg = i18nc("@info:status",
"Generating diff for <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Could not get <application>Hg</application> repository diff.");
m_operationCompletedMsg = i18nc("@info:status",
"Generated <application>Hg</application> diff successfully.");
emit infoMessage(infoMsg);
QStringList args;
args << QLatin1String("--config");
args << QLatin1String("extensions.hgext.extdiff=");
args << QLatin1String("-p");
args << this->visualDiffExecPath();
if (m_contextItems.length() == 1) {
args << m_contextItems.takeFirst().localPath();
}
m_hgWrapper->executeCommand(QLatin1String("extdiff"), args);
}
void FileViewHgPlugin::serve()
{
clearMessages();
HgServeDialog diag;
diag.exec();
}
void FileViewHgPlugin::backout()
{
clearMessages();
m_hgWrapper = HgWrapper::instance();
if (!m_hgWrapper->isWorkingDirectoryClean()) {
KMessageBox::error(0, i18nc("@message:error",
"abort: Uncommitted changes in working directory!"));
return;
}
HgBackoutDialog diag;
diag.exec();
}
void FileViewHgPlugin::rollback()
{
// execute a dry run rollback first to see if there is anything to
// be rolled back, or check what will be rolled back
if (!m_hgWrapper->rollback(true)) {
KMessageBox::error(0, i18nc("@info:message", "No rollback "
"information available!"));
return;
}
// get what will be rolled back
QString lastTransaction = m_hgWrapper->readAllStandardOutput();
int cutOfFrom = lastTransaction.indexOf(QRegExp("\\d"));
lastTransaction = lastTransaction.mid(cutOfFrom);
// ask
int answer = KMessageBox::questionYesNo(0, i18nc("@message:yesorno",
"Would you like to rollback last transaction?")
+ "\nrevision: " + lastTransaction);
if (answer == KMessageBox::No) {
return;
}
QString infoMsg = i18nc("@info:status",
"Executing Rollback <application>Hg</application> repository...");
m_errorMsg = i18nc("@info:status",
"Rollback of <application>Hg</application> repository failed.");
m_operationCompletedMsg = i18nc("@info:status",
"Rollback of <application>Hg</application> repository completed successfully.");
emit infoMessage(infoMsg);
m_hgWrapper->rollback();
KMessageBox::information(0, m_hgWrapper->readAllStandardOutput());
emit itemVersionsChanged();
}
void FileViewHgPlugin::slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus)
{
if ((exitStatus != QProcess::NormalExit) || (exitCode != 0)) {
emit errorMessage(m_errorMsg);
}
else {
m_contextItems.clear();
emit operationCompletedMessage(m_operationCompletedMsg);
emit itemVersionsChanged();
}
}
void FileViewHgPlugin::slotOperationError()
{
m_contextItems.clear();
emit errorMessage(m_errorMsg);
}
void FileViewHgPlugin::clearMessages() const
{
m_operationCompletedMsg.clear();
m_errorMsg.clear();
}
QString FileViewHgPlugin::visualDiffExecPath()
{
KUrl url = KUrl::fromPath(QDir::homePath());
url.addPath(".dolphin-hg");
KConfig config(url.path(), KConfig::SimpleConfig);
KConfigGroup group(&config, QLatin1String("diff"));
QString result = group.readEntry(QLatin1String("exec"), QString()).trimmed();
if (result.length() > 0) {
return result;
}
KService::List services = KMimeTypeTrader::self()->query("text/x-diff");
return services.first()->exec().split(' ').takeFirst();
}
#include "moc_fileviewhgplugin.cpp"

View file

@ -0,0 +1,46 @@
[Desktop Entry]
Type=Service
Name=Mercurial
Name[ar]=Mercurial
Name[bs]=Mercurial
Name[ca]=Mercurial
Name[ca@valencia]=Mercurial
Name[cs]=Mercurial
Name[da]=Mercurial
Name[de]=Mercurial
Name[el]=Mercurial
Name[en_GB]=Mercurial
Name[es]=Mercurial
Name[et]=Mercurial
Name[fi]=Mercurial
Name[fr]=Mercurial
Name[gl]=Mercurial
Name[hu]=Mercurial
Name[it]=Mercurial
Name[kk]=Mercurial
Name[ko]=Mercurial
Name[lt]=Mercurial
Name[mr]=ि
Name[nb]=Mercurial
Name[nl]=Mercurial
Name[pa]=
Name[pl]=Mercurial
Name[pt]=Mercurial
Name[pt_BR]=Mercurial
Name[ro]=Mercurial
Name[ru]=Mercurial
Name[sk]=Mercurial
Name[sl]=Mercurial
Name[sr]=Меркјуријал
Name[sr@ijekavian]=Меркјуријал
Name[sr@ijekavianlatin]=Mercurial
Name[sr@latin]=Mercurial
Name[sv]=Mercurial
Name[tr]=Mercurial
Name[uk]=Mercurial
Name[x-test]=xxMercurialxx
Name[zh_CN]=Mercurial
Name[zh_TW]=Mercurial
X-KDE-ServiceTypes=FileViewVersionControlPlugin
MimeType=text/plain;
X-KDE-Library=fileviewhgplugin

View file

@ -0,0 +1,142 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef FILEVIEWHGPLUGIN_H
#define FILEVIEWHGPLUGIN_H
#include "hgwrapper.h"
#include <kfileitem.h>
#include <kversioncontrolplugin.h>
#include <QtCore/QHash>
#include <QtCore/QString>
#include <QtCore/QProcess>
class KAction;
class KMenu;
class FileViewHgPlugin : public KVersionControlPlugin
{
Q_OBJECT
public:
FileViewHgPlugin(QObject *parent, const QList<QVariant> &args);
virtual ~FileViewHgPlugin();
virtual QString fileName() const;
virtual bool beginRetrieval(const QString &directory);
virtual void endRetrieval();
virtual KVersionControlPlugin::ItemVersion itemVersion(const KFileItem &item) const;
virtual QList<QAction*> actions(const KFileItemList &items) const;
private:
/**
* Check if HgWrapper is created and connect some signals/slots. Created
* to ensure that HgWrapper singleton is instantiated not during
* plugin contruction hence not in other thread which ends up giving
* a lot of warnings.
*/
void createHgWrapper() const;
/**
* Simply clear status messages ie m_errorMsg and m_operationCompletedMsg
*/
void clearMessages() const;
/**
* Read executable file path to open diff patches with from
* $HOME/.dolphin-hg file in INI format
*/
QString visualDiffExecPath();
QList<QAction*> itemContextMenu(const KFileItemList &items) const;
QList<QAction*> directoryContextMenu(const QString &directory) const;
QList<QAction*> universalContextMenuActions(const QString &directory) const;
private slots:
void addFiles();
void removeFiles();
void renameFile();
void commit();
void branch();
void tag();
void update();
void clone();
void create();
void global_config();
void repo_config();
void push();
void pull();
void revert();
void revertAll();
void rollback();
void backout();
void diff();
void serve();
void merge();
void bundle();
void unbundle();
void exportChangesets();
void importChangesets();
void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
void slotOperationError();
private:
QHash<QString, ItemVersion> m_versionInfoHash;
KMenu *m_mainContextMenu;
KAction *m_menuAction;
KAction *m_addAction;
KAction *m_removeAction;
KAction *m_renameAction;
KAction *m_commitAction;
KAction *m_branchAction;
KAction *m_tagAction;
KAction *m_updateAction;
KAction *m_cloneAction;
KAction *m_createAction;
KAction *m_globalConfigAction;
KAction *m_repoConfigAction;
KAction *m_pushAction;
KAction *m_pullAction;
KAction *m_revertAction;
KAction *m_revertAllAction;
KAction *m_rollbackAction;
KAction *m_mergeAction;
KAction *m_bundleAction;
KAction *m_exportAction;
KAction *m_unbundleAction;
KAction *m_importAction;
KAction *m_diffAction;
KAction *m_serveAction;
KAction *m_backoutAction;
mutable KFileItemList m_contextItems;
mutable QString m_universalCurrentDirectory;
mutable QString m_currentDir;
mutable QString m_operationCompletedMsg;
mutable QString m_errorMsg;
mutable HgWrapper *m_hgWrapper;
HgWrapper *m_retrievalHgw;
};
#endif // FILEVIEWHGPLUGIN_H

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE kcfg SYSTEM "http://www.kde.org/standards/kcfg/1.0/kcfg.dtd">
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0">
<kcfgfile name="fileviewhgpluginrc"/>
<group name="CommitDialogSettings">
<entry name="commitDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
<min>400</min>
</entry>
<entry name="commitDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
<min>500</min>
</entry>
</group>
<group name="ConfigDialogSettings">
<entry name="configDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
<min>400</min>
</entry>
<entry name="configDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
<min>500</min>
</entry>
</group>
<group name="CloneDialogSettings">
<entry name="cloneDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="cloneDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="PushDialogSettings">
<entry name="pushDialogBigHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="pushDialogBigWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="PullDialogSettings">
<entry name="pullDialogBigHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="pullDialogBigWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="MergeDialogSettings">
<entry name="mergeDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="mergeDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="BundleDialogSettings">
<entry name="bundleDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="bundleDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="ExportDialogSettings">
<entry name="exportDialogHeight" type="Int">
<label>Dialog height</label>
<default>550</default>
</entry>
<entry name="exportDialogWidth" type="Int">
<label>Dialog width</label>
<default>900</default>
</entry>
</group>
<group name="ImportDialogSettings">
<entry name="importDialogHeight" type="Int">
<label>Dialog height</label>
<default>540</default>
</entry>
<entry name="importDialogWidth" type="Int">
<label>Dialog width</label>
<default>500</default>
</entry>
</group>
<group name="ServeDialogSettings">
<entry name="serveDialogHeight" type="Int">
<label>Dialog height</label>
<default>600</default>
</entry>
<entry name="serveDialogWidth" type="Int">
<label>Dialog width</label>
<default>300</default>
</entry>
</group>
<group name="BackoutDialogSettings">
<entry name="backoutDialogHeight" type="Int">
<label>Dialog height</label>
<default>346</default>
</entry>
<entry name="backoutDialogWidth" type="Int">
<label>Dialog width</label>
<default>537</default>
</entry>
</group>
</kcfg>

View file

@ -0,0 +1,4 @@
File=fileviewhgpluginsettings.kcfg
ClassName=FileViewHgPluginSettings
Singleton=true
Mutators=true

View file

@ -0,0 +1,158 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "hgconfig.h"
#include "hgwrapper.h"
#include <QtCore/QDir>
#include <kdebug.h>
#include <kurl.h>
#include <kconfig.h>
#include <kconfiggroup.h>
HgConfig::HgConfig(ConfigType configType) :
m_configType(configType),
m_config(0)
{
getConfigFilePath();
loadConfig();
}
HgConfig::~HgConfig()
{
delete m_config;
}
QString HgConfig::configFilePath() const
{
return m_configFilePath;
}
bool HgConfig::getConfigFilePath()
{
switch (m_configType) {
case RepoConfig:
{
KUrl repoBase = KUrl(HgWrapper::instance()->getBaseDir());
repoBase.addPath(QLatin1String(".hg/hgrc"));
m_configFilePath = repoBase.path();
break;
}
case GlobalConfig:
{
KUrl homeUrl = KUrl(QDir::homePath());
homeUrl.addPath(QLatin1String(".hgrc"));
m_configFilePath = homeUrl.path();
break;
}
case TempConfig:
break;
}
return true;
}
bool HgConfig::loadConfig()
{
m_config = new KConfig(m_configFilePath, KConfig::SimpleConfig);
return true;
}
QString HgConfig::property(const QString &section,
const QString &propertyName) const
{
KConfigGroup group(m_config, section);
return group.readEntry(propertyName, QString()).trimmed();
}
void HgConfig::setProperty(const QString &section,
const QString &propertyName,
const QString &propertyValue)
{
KConfigGroup uiGroup(m_config, section);
if (propertyValue.isEmpty()) {
uiGroup.deleteEntry(propertyName, KConfigGroup::Normal);
return;
}
uiGroup.writeEntry(propertyName, propertyValue.trimmed());
}
/* User Interface [ui] Section */
QString HgConfig::username() const
{
return property(QLatin1String("ui"), QLatin1String("username"));
}
void HgConfig::setUsername(const QString &userName)
{
setProperty(QLatin1String("ui"), QLatin1String("username"), userName);
}
QString HgConfig::editor() const
{
return property(QLatin1String("ui"), QLatin1String("editor"));
}
void HgConfig::setEditor(const QString &pathToEditor)
{
setProperty(QLatin1String("ui"), QLatin1String("editor"), pathToEditor);
}
QString HgConfig::merge() const
{
return property(QLatin1String("ui"), QLatin1String("merge"));
}
void HgConfig::setMerge(const QString &pathToMergeTool)
{
setProperty(QLatin1String("ui"), QLatin1String("merge"), pathToMergeTool);
}
/* Repo specific */
void HgConfig::setRepoRemotePath(const QString &alias, const QString &url)
{
Q_ASSERT(m_configType == RepoConfig);
setProperty(QLatin1String("paths"), alias, url);
}
void HgConfig::deleteRepoRemotePath(const QString &alias)
{
Q_ASSERT(m_configType == RepoConfig);
KConfigGroup group(m_config, QLatin1String("paths"));
group.deleteEntry(alias);
}
QString HgConfig::repoRemotePath(const QString &alias) const
{
Q_ASSERT(m_configType == RepoConfig);
return property(QLatin1String("paths"), alias);
}
QMap<QString, QString> HgConfig::repoRemotePathList() const
{
Q_ASSERT(m_configType == RepoConfig);
KConfigGroup group(m_config, QLatin1String("paths"));
return group.entryMap();
}
//

View file

@ -0,0 +1,132 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGCONFIG_H
#define HGCONFIG_H
#include <QtCore/QString>
#include <QtCore/QProcess>
#include <QtCore/QMap>
class KConfig;
/**
* Provides a wrapper to read and write Mercurial settings in hgrc files.
* Also provides interface to read/write other settings as well, for which
* a direct function is not provided.
*/
class HgConfig
{
public:
/**
* Type of hgrc file.
*
* RepoConfig: hgrc of the local/current repository.
* GlobalConfig: Global hgrc file. Under *nix, ~/.hgrc file
* TempConfig: A temporary config file, that can be used by some commands
* for just one time. Usually after taking input from user to
* override default settings.
*/
enum ConfigType {
RepoConfig, GlobalConfig, TempConfig
};
HgConfig(ConfigType configFile);
~HgConfig();
// Related to config file
/**
* Return the path of hgrc file currently loaded
*/
QString configFilePath() const;
// Repo specific
/**
* Set path of repository associated with given given alias
*/
void setRepoRemotePath(const QString &alias, const QString &url);
/**
* Delete alias/path of repository associated with given given alias
*/
void deleteRepoRemotePath(const QString &alias);
/**
* Return path of repository associated with given given alias
*/
QString repoRemotePath(const QString &alias) const;
/**
* Return a list of alias-path pair of remote repository paths
*/
QMap<QString, QString> repoRemotePathList() const;
///////////
/**
* Get the value of a property in a given section.
*
* @param section The settings group in hgrc file.
* @param propertyName Name of the property in section whose value is\
* required
* @return Value of property in the section given.
*/
QString property(const QString &section, const QString &propertyName)const;
/**
* Set the value of a property in a given section.
*
* @param section The settings group in hgrc file.
* @param propertyName Name of the property in section whose value is
* to be modified.
* @param propertyValue Value to be set of given propery. Deletes the
* entry if empty.
*/
void setProperty(const QString &section, const QString &propertyName,
const QString &propertyValue);
// user interface section
QString username() const;
void setUsername(const QString &userName);
QString editor() const;
void setEditor(const QString &pathToEditor);
QString merge() const;
void setMerge(const QString &pathToMergeTool);
private:
/**
* Used during construction to determine the path of config files
* based on given ConfigType enum
*/
bool getConfigFilePath();
bool loadConfig();
private:
ConfigType m_configType;
QString m_configFilePath;
KConfig *m_config;
};
#endif //HGCONFIG_H

View file

@ -0,0 +1,410 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "hgwrapper.h"
#include <QtGui/QApplication>
#include <QtCore/QTextCodec>
#include <kdebug.h>
#include <kurl.h>
//TODO: Replace start() with executeCommand functions wherever possible.
//FIXME: Add/Remove/Revert argument length limit. Divide the list.
//FIXME: Cannot create thread for parent that is in different thread.
HgWrapper *HgWrapper::m_instance = 0;
HgWrapper::HgWrapper(QObject *parent) :
QObject(parent)
{
m_localCodec = QTextCodec::codecForLocale();
// re-emit QProcess signals
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SIGNAL(error(QProcess::ProcessError)));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SIGNAL(finished(int, QProcess::ExitStatus))),
connect(&m_process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SIGNAL(stateChanged(QProcess::ProcessState)));
connect(&m_process, SIGNAL(started()),
this, SIGNAL(started()));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationCompleted(int, QProcess::ExitStatus)));
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotOperationError(QProcess::ProcessError)));
}
HgWrapper *HgWrapper::instance()
{
if (!m_instance) {
m_instance = new HgWrapper;
}
return m_instance;
}
void HgWrapper::freeInstance()
{
delete m_instance;
m_instance = 0;
}
void HgWrapper::slotOperationCompleted(int exitCode,
QProcess::ExitStatus exitStatus)
{
kDebug() << "'hg' Exit Code: " << exitCode << " Exit Status: "
<< exitStatus;
if (m_primaryOperation) {
emit primaryOperationFinished(exitCode, exitStatus);
}
}
void HgWrapper::slotOperationError(QProcess::ProcessError error)
{
kDebug() << "Error occurred while executing 'hg' with arguments ";
if (m_primaryOperation) {
emit primaryOperationError(error);
}
}
bool HgWrapper::executeCommand(const QString &hgCommand,
const QStringList &arguments,
QString &output,
bool primaryOperation)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
executeCommand(hgCommand, arguments, primaryOperation);
m_process.waitForFinished();
output = QTextCodec::codecForLocale()->toUnicode(m_process.readAllStandardOutput());
return (m_process.exitStatus() == QProcess::NormalExit &&
m_process.exitCode() == 0);
}
void HgWrapper::executeCommand(const QString &hgCommand,
const QStringList &arguments,
bool primaryOperation)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
m_primaryOperation = primaryOperation;
if (m_primaryOperation) {
kDebug() << "Primary operation";
}
QStringList args;
args << hgCommand;
args << arguments;
m_process.setWorkingDirectory(m_currentDir);
m_process.start(QLatin1String("hg"), args);
}
bool HgWrapper::executeCommandTillFinished(const QString &hgCommand,
const QStringList &arguments,
bool primaryOperation)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
m_primaryOperation = primaryOperation;
QStringList args;
args << hgCommand;
args << arguments;
m_process.setWorkingDirectory(m_currentDir);
m_process.start(QLatin1String("hg"), args);
m_process.waitForFinished();
return (m_process.exitStatus() == QProcess::NormalExit &&
m_process.exitCode() == 0);
}
QString HgWrapper::getBaseDir() const
{
return m_hgBaseDir;
}
QString HgWrapper::getCurrentDir() const
{
return m_currentDir;
}
void HgWrapper::updateBaseDir()
{
m_process.setWorkingDirectory(m_currentDir);
m_process.start(QLatin1String("hg root"));
m_process.waitForFinished();
m_hgBaseDir = QString(m_process.readAllStandardOutput()).trimmed();
}
void HgWrapper::setCurrentDir(const QString &directory)
{
m_currentDir = directory;
updateBaseDir(); //now get root directory of repository
}
void HgWrapper::setBaseAsWorkingDir()
{
m_process.setWorkingDirectory(getBaseDir());
}
void HgWrapper::addFiles(const KFileItemList &fileList)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
QStringList args;
args << QLatin1String("add");
foreach (const KFileItem &item, fileList) {
args << item.localPath();
}
m_process.start(QLatin1String("hg"), args);
}
bool HgWrapper::renameFile(const QString &source, const QString &destination)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
QStringList args;
args << source << destination;
executeCommand(QLatin1String("rename"), args, true);
m_process.waitForFinished();
return (m_process.exitStatus() == QProcess::NormalExit &&
m_process.exitCode() == 0);
}
void HgWrapper::removeFiles(const KFileItemList &fileList)
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
QStringList args;
args << QLatin1String("remove");
args << QLatin1String("--force");
foreach (const KFileItem &item, fileList) {
args << item.localPath();
}
m_process.start(QLatin1String("hg"), args);
}
bool HgWrapper::commit(const QString &message, const QStringList &files,
bool closeCurrentBranch)
{
QStringList args;
args << files;
args << QLatin1String("-m") << message;
if (closeCurrentBranch) {
args << "--close-branch";
}
executeCommand(QLatin1String("commit"), args, true);
m_process.waitForFinished();
return (m_process.exitCode() == 0 &&
m_process.exitStatus() == QProcess::NormalExit);
}
bool HgWrapper::createBranch(const QString &name)
{
QStringList args;
args << name;
executeCommand(QLatin1String("branch"), args, true);
m_process.waitForFinished();
return (m_process.exitCode() == 0 &&
m_process.exitStatus() == QProcess::NormalExit);
}
bool HgWrapper::switchBranch(const QString &name)
{
QStringList args;
args << QLatin1String("-c") << name;
executeCommand(QLatin1String("update"), args, true);
m_process.waitForFinished();
return (m_process.exitCode() == 0 &&
m_process.exitStatus() == QProcess::NormalExit);
}
bool HgWrapper::createTag(const QString &name)
{
QStringList args;
args << name;
executeCommand(QLatin1String("tag"), args, true);
m_process.waitForFinished();
return (m_process.exitCode() == 0 &&
m_process.exitStatus() == QProcess::NormalExit);
}
bool HgWrapper::revertAll()
{
QStringList args;
args << "--all";
return executeCommandTillFinished(QLatin1String("revert"), args, true);
}
bool HgWrapper::revert(const KFileItemList &fileList)
{
QStringList arguments;
foreach (const KFileItem &item, fileList) {
arguments << item.localPath();
}
return executeCommandTillFinished(QLatin1String("revert"), arguments, true);
}
bool HgWrapper::rollback(bool dryRun)
{
QStringList args;
if (dryRun) {
args << QLatin1String("-n");
}
return executeCommandTillFinished(QLatin1String("rollback"), args, true);
}
bool HgWrapper::switchTag(const QString &name)
{
QStringList args;
args << QLatin1String("-c") << name;
executeCommand(QLatin1String("update"), args, true);
m_process.waitForFinished();
return (m_process.exitCode() == 0 &&
m_process.exitStatus() == QProcess::NormalExit);
}
//TODO: Make it return QStringList.
QString HgWrapper::getParentsOfHead()
{
Q_ASSERT(m_process.state() == QProcess::NotRunning);
QString output;
QStringList args;
args << QLatin1String("--template");
args << QLatin1String("{rev}:{node|short} ");
executeCommand(QLatin1String("parents"), args, output);
return output;
}
QStringList HgWrapper::getTags()
{
QStringList result;
executeCommand(QLatin1String("tags"));
while (m_process.waitForReadyRead()) {
char buffer[1048];
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
result << QString(buffer).split(QRegExp("\\s+"),
QString::SkipEmptyParts).first();
}
}
return result;
}
QStringList HgWrapper::getBranches()
{
QStringList result;
executeCommand(QLatin1String("branches"));
while (m_process.waitForReadyRead()) {
char buffer[1048];
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
// 'hg branches' command lists the branches in following format
// <branchname> <revision:changeset_hash> [(inactive)]
// Extract just the branchname
result << QString(buffer).remove(QRegExp("[\\s]+[\\d:a-zA-Z\\(\\)]*"));
}
}
return result;
}
void HgWrapper::getItemVersions(QHash<QString, KVersionControlPlugin::ItemVersion> &result)
{
/*int nTrimOutLeft = m_hgBaseDir.length();
QString relativePrefix = m_currentDir.right(m_currentDir.length() -
nTrimOutLeft - 1);
kDebug() << m_hgBaseDir << " " << relativePrefix;*/
// Get status of files
QStringList args;
args << QLatin1String("status");
args << QLatin1String("--modified");
args << QLatin1String("--added");
args << QLatin1String("--removed");
args << QLatin1String("--deleted");
args << QLatin1String("--unknown");
args << QLatin1String("--ignored");
m_process.setWorkingDirectory(m_currentDir);
m_process.start(QLatin1String("hg"), args);
while (m_process.waitForReadyRead()) {
char buffer[1024];
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
const QString currentLine(QTextCodec::codecForLocale()->toUnicode(buffer).trimmed());
char currentStatus = buffer[0];
QString currentFile = currentLine.mid(2);
KVersionControlPlugin::ItemVersion vs = KVersionControlPlugin::NormalVersion;
switch (currentStatus) {
case 'A':
vs = KVersionControlPlugin::AddedVersion;
break;
case 'M':
vs = KVersionControlPlugin::LocallyModifiedVersion;
break;
case '?':
vs = KVersionControlPlugin::UnversionedVersion;
break;
case 'R':
vs = KVersionControlPlugin::RemovedVersion;
break;
case 'I':
vs = KVersionControlPlugin::IgnoredVersion;
break;
case 'C':
vs = KVersionControlPlugin::NormalVersion;
break;
case '!':
vs = KVersionControlPlugin::MissingVersion;
break;
}
if (vs != KVersionControlPlugin::NormalVersion) {
// Get full path to file and insert it to result
KUrl url = KUrl::fromPath(m_hgBaseDir);
url.addPath(currentFile);
QString filePath = url.path();
result.insert(filePath, vs);
}
}
}
}
void HgWrapper::terminateCurrentProcess()
{
kDebug() << "terminating";
m_process.terminate();
}
bool HgWrapper::isWorkingDirectoryClean()
{
QStringList args;
args << QLatin1String("--modified");
args << QLatin1String("--added");
args << QLatin1String("--removed");
args << QLatin1String("--deleted");
QString output;
executeCommand(QLatin1String("status"), args, output);
return output.trimmed().isEmpty();
}
#include "moc_hgwrapper.cpp"

View file

@ -0,0 +1,279 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGWRAPPER_H
#define HGWRAPPER_H
#include <QtCore/QProcess>
#include <QtCore/QString>
#include <QtCore/QHash>
#include <QtCore/QTextCodec>
#include <kfileitem.h>
#include <kversioncontrolplugin.h>
#include <QTextCodec>
//TODO: Create signals for infoMessage and errorMessage which will be
// caught by main plugin interface.
/**
* A singleton class providing implementation of many Mercurial commands
*/
class HgWrapper : public QObject
{
Q_OBJECT
public:
HgWrapper(QObject *parent = 0);
static HgWrapper *instance();
static void freeInstance();
/**
* Start a mercurial command with given arguments.
*
* @param hgCommand Command to be executed. eg. diff, status
* @param arguments Arguments for the given command
* @param primaryOperation Will emit primaryOperationFinished,
* primaryOperationError signals.
*/
void executeCommand(const QString &hgCommand,
const QStringList &arguments = QStringList(),
bool primaryOperation=false);
/**
* Start a mercurial command with given arguments and return until
* process completes.
*
* @param hgCommand Command to be executed. eg. diff, status
* @param arguments Arguments for the given command
* @param primaryOperation Will emit primaryOperationCompleted,
* primaryOperationError signals.
* @return true if operations completed successfully, otherwise false
*/
bool executeCommandTillFinished(const QString &hgCommand,
const QStringList &arguments = QStringList(),
bool primaryOperation=false);
/**
* Start a mercurial command with given arguments, write standard output
* to output parameter and return till finished.
*
* @param hgCommand Command to be executed. eg. diff, status
* @param arguments Arguments for the given command
* @param output Append standard output of process to this string
* @param primaryOperation Will emit primaryOperationCompleted,
* primaryOperationError signals.
* @return true if operations completed successfully, otherwise false
*/
bool executeCommand(const QString &hgCommand,
const QStringList &arguments,
QString &output,
bool primaryOperation=false);
/**
* Get the root directory of Mercurial repository. Using 'hg root'
*
* @return String containing path of the root directory.
*/
QString getBaseDir() const;
/**
* Sets the current directory being browsed with plugin enabled.
* Updates base directory of repository accordingly
*/
void setCurrentDir(const QString &directory);
/**
* Get the directory path that is currently used as the working directory
* to execute the commands by the HgWrapper.
*/
QString getCurrentDir() const;
/**
* Set the root directory of repository as working directory.
*/
void setBaseAsWorkingDir();
/**
* Get FileName-ItemVersion pairs of the repository returned by
*
* $hg status --modified --added --removed --deleted --unknown --ignored
*
* Hence returns files with ItemVersion
* - LocallyModifiedVersion
* - AddedVersion
* - RemovedVersion
* - RemovedVersion
* - UnversionedVersion
* - IgnoredVersion
* - MissingVersion
*
* @param result A hashmap containing FileName-ItemVersion pairs
*
*/
void getItemVersions(QHash<QString, KVersionControlPlugin::ItemVersion> &result);
void addFiles(const KFileItemList &fileList);
void removeFiles(const KFileItemList &fileList);
bool renameFile(const QString &source, const QString &destination);
/**
* Commits changes made to the working directory.
* @param message Commit message. Should not be empty.
* @param files List of files to be committed. Files changed but not
* listed here will be ignored during commit.
* If the list is empty, all modified files will be
* committed, the deault behovior.
* @param closeCurrentBranch Closes the current branch after commit.
* @return true if successful, otherwise false
*/
bool commit(const QString &message,
const QStringList &files = QStringList(),
bool closeCurrentBranch = false);
/**
* Create a new branch
* @param name Name of new branch to be createdialog
* @return true if successfully created, otherwise false
*/
bool createBranch(const QString &name);
/**
* Update current working directory to another branch
* @param name Name of the branch to which working directory
* has to be updated.
* @return true if successful, otherwise false
*/
bool switchBranch(const QString &name);
/**
* Create tag for current changeset(the changeset of working directory)
* @param name Name of the new tag to be createdialog
* @return true if successful, otherwise false
*/
bool createTag(const QString &name);
/**
* Update working directory to a changeset named by given tag
* @param name Tag of the changeset to which working directory
* has to be updated.
* @return true if successful, otherwise false
*/
bool switchTag(const QString &name);
/**
* Reverts all local changes made to working directory. Will update to
* last changeset of current branch, ie state just after last commit.
*/
bool revertAll();
/**
* Reverts local changes made to selected files. All changes made to
* these files after last commit will be lost.
*/
bool revert(const KFileItemList &fileList);
/**
* Undo's last transaction. Like commit, pull, push(to this repo).
* Does not alter working directory.
*
* Use with care. Rollback cant be undone. See Mercurial man page FOR
* more info.
*
* @param dryRun Do not actually perform action, but just print output
* Used to check if Rollback can be done, and if yes then
* what will be rolled back.
* @return true if successful, otherwise false
*/
bool rollback(bool dryRun=false);
/**
* Checks if the working directory is clean, ie there are no
* uncommitted changes present.
*
* @return true if clean otherwise false
*/
bool isWorkingDirectoryClean();
QString getParentsOfHead();
/**
* Returns list of all branch names.
*/
QStringList getBranches();
/**
* Returns list of all tags
*/
QStringList getTags();
inline QString readAllStandardOutput() {
return QTextCodec::codecForLocale()->toUnicode(m_process.readAllStandardOutput());
}
inline QString readAllStandardError() {
return QTextCodec::codecForLocale()->toUnicode(m_process.readAllStandardError());
}
/**
* Check if some Mercurial operation is currently being executed or
* about to be started.
*/
inline bool isBusy() {
return (m_process.state() == QProcess::Running ||
m_process.state() == QProcess::Starting);
}
public slots:
/**
* Try to terminate the currently running operation.
*/
void terminateCurrentProcess();
signals:
///equivalent to the signals of QProcess
void finished(int exitCode, QProcess::ExitStatus exitStatus);
void error(QProcess::ProcessError error);
void started();
void stateChanged(QProcess::ProcessState state);
void primaryOperationFinished(int exitCode, QProcess::ExitStatus exitStatus);
void primaryOperationError(QProcess::ProcessError error);
private:
///Get and update m_hgBaseDir
void updateBaseDir();
private slots:
void slotOperationCompleted(int exitCode, QProcess::ExitStatus exitStatus);
void slotOperationError(QProcess::ProcessError error);
private:
static HgWrapper *m_instance;
QProcess m_process;
QTextCodec *m_localCodec;
QString m_hgBaseDir;
QString m_currentDir;
bool m_primaryOperation; // to differentiate intermediate process
};
#endif // HGWRAPPER_H

View file

@ -0,0 +1,221 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "importdialog.h"
#include "fileviewhgpluginsettings.h"
#include "commititemdelegate.h"
#include "hgwrapper.h"
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QListWidget>
#include <QtCore/QProcess>
#include <QtCore/QTextCodec>
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <klineedit.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kpushbutton.h>
#include <kfiledialog.h>
HgImportDialog::HgImportDialog(QWidget *parent) :
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Import"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Import"));
//
setupUI();
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->importDialogWidth(),
settings->importDialogHeight()));
//
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
connect(m_addPatches, SIGNAL(clicked()),
this, SLOT(slotAddPatches()));
connect(m_removePatches, SIGNAL(clicked()),
this, SLOT(slotRemovePatches()));
}
void HgImportDialog::setupUI()
{
QGroupBox *mainGroup = new QGroupBox;
QGridLayout *mainLayout = new QGridLayout;
m_patchList = new QListWidget;
m_patchList->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_patchList->setItemDelegate(new CommitItemDelegate);
mainLayout->addWidget(m_patchList);
mainGroup->setLayout(mainLayout);
// options
m_optionGroup = new QGroupBox(i18nc("@label:group", "Options"));
m_optNoCommit = new QCheckBox(i18nc("@label",
"Do not commit, just update the working directory"));
m_optForce = new QCheckBox(i18nc("@label",
"Skip test for outstanding uncommitted changes"));
m_optExact = new QCheckBox(i18nc("@label",
"Apply patch to the nodes from which it was generated"));
m_optBypass = new QCheckBox(i18nc("@label",
"Apply patch without touching working directory"));
QVBoxLayout *optionLayout = new QVBoxLayout;
optionLayout->addWidget(m_optNoCommit);
optionLayout->addWidget(m_optForce);
optionLayout->addWidget(m_optExact);
optionLayout->addWidget(m_optBypass);
m_optionGroup->setLayout(optionLayout);
// top buttons
QHBoxLayout *topButtons = new QHBoxLayout;
m_addPatches = new KPushButton(i18nc("@label:button",
"Add Patches"));
m_removePatches = new KPushButton(i18nc("@label:button",
"Remove Patches"));
topButtons->addWidget(m_addPatches);
topButtons->addWidget(m_removePatches);
topButtons->addStretch();
//setup main dialog widget
QWidget *widget = new QWidget;
QVBoxLayout *layout = new QVBoxLayout;
layout->addLayout(topButtons);
layout->addWidget(mainGroup);
layout->addWidget(m_optionGroup);
widget->setLayout(layout);
setMainWidget(widget);
}
void HgImportDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setImportDialogHeight(this->height());
settings->setImportDialogWidth(this->width());
settings->writeConfig();
}
void HgImportDialog::done(int r)
{
if (r == KDialog::Accepted) {
QStringList args;
if (m_optForce->checkState() == Qt::Checked) {
args << QLatin1String("--force");
}
if (m_optBypass->checkState() == Qt::Checked) {
args << QLatin1String("--bypass");
}
if (m_optNoCommit->checkState() == Qt::Checked) {
args << QLatin1String("--no-commit");
}
if (m_optExact->checkState() == Qt::Checked) {
args << QLatin1String("--exact");
}
int countRows = m_patchList->count();
for (int i=0; i<countRows; i++) {
QListWidgetItem *item = m_patchList->item(i);
args << item->data(Qt::UserRole + 5).toString();
}
HgWrapper *hgw = HgWrapper::instance();
if (hgw->executeCommandTillFinished(QLatin1String("import"), args)) {
KDialog::done(r);
}
else {
KMessageBox::error(this, hgw->readAllStandardError());
}
}
else {
KDialog::done(r);
}
}
void HgImportDialog::getPatchInfo(const QString &fileName)
{
QFile file(fileName);
file.open(QFile::ReadOnly);
QTextStream fileStream(&file);
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::UserRole + 1, QString());
item->setData(Qt::UserRole + 2, QString());
item->setData(Qt::UserRole + 5, fileName);
bool gotInfo = false;
do {
QString line = fileStream.readLine();
if (line.startsWith(QLatin1String("diff"))) {
break;
}
else if (line.startsWith(QLatin1String("# User"))) {
item->setData(Qt::UserRole + 3,
line.remove(QLatin1String("# User")).trimmed());
}
else if (line.startsWith(QLatin1String("# Node ID"))) {
QString node = line.remove(QLatin1String("# Node ID")).trimmed();
if (!m_patchList->findItems(node, Qt::MatchExactly).empty()) {
return;
}
item->setData(Qt::DisplayRole, node);
}
else if (line.startsWith(QLatin1String("# Parent"))) {
gotInfo = true;
}
else if (gotInfo) {
item->setData(Qt::UserRole + 4, line.trimmed());
break;
}
} while (!fileStream.atEnd());
m_patchList->addItem(item);
file.close();
}
void HgImportDialog::slotAddPatches()
{
QStringList patches = KFileDialog::getOpenFileNames();
foreach (QString fileName, patches) {
getPatchInfo(fileName);
}
}
void HgImportDialog::slotRemovePatches()
{
int count = m_patchList->count();
for (int i=0; i<count; i++) {
m_patchList->takeItem(i);
}
}
#include "moc_importdialog.cpp"

View file

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGIMPORTDIALOG_H
#define HGIMPORTDIALOG_H
#include <kdialog.h>
#include <QListWidget>
#include <QCheckBox>
#include <QGroupBox>
class KLineEdit;
/**
* Implemets dialog to import changesets from patch files generated by
* Mercurial's export command
*/
class HgImportDialog : public KDialog
{
Q_OBJECT
public:
HgImportDialog(QWidget *parent=0);
public slots:
void done(int r);
private slots:
void saveGeometry();
void slotAddPatches();
void slotRemovePatches();
private:
void setupUI();
void getPatchInfo(const QString &fileName);
private:
QListWidget *m_patchList;
KPushButton *m_addPatches;
KPushButton *m_removePatches;
//options
QGroupBox *m_optionGroup;
QCheckBox *m_optNoCommit;
QCheckBox *m_optBypass;
QCheckBox *m_optExact;
QCheckBox *m_optForce;
};
#endif /* HGIMPORTDIALOG_H */

View file

@ -0,0 +1,162 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "mergedialog.h"
#include "hgwrapper.h"
#include "commititemdelegate.h"
#include "commitinfowidget.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QTextEdit>
#include <QtGui/qlistwidget.h>
#include <QtCore/QTextCodec>
#include <kpushbutton.h>
#include <kcombobox.h>
#include <klocale.h>
#include <klineedit.h>
#include <kdebug.h>
#include <kmessagebox.h>
HgMergeDialog::HgMergeDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Merge"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setButtonText(KDialog::Ok, i18nc("@label:button", "Merge"));
// UI
m_currentChangeset = new QLabel;
m_commitInfoWidget = new HgCommitInfoWidget;
QVBoxLayout *vbox = new QVBoxLayout;
vbox->addWidget(m_currentChangeset);
vbox->addWidget(m_commitInfoWidget);
QWidget *widget = new QWidget;
widget->setLayout(vbox);
setMainWidget(widget);
updateInitialDialog();
// load saved geometry
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->mergeDialogWidth(),
settings->mergeDialogHeight()));
// connections
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
}
void HgMergeDialog::updateInitialDialog()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update label - current branch
QString line("<b>parents:</b> ");
line += hgWrapper->getParentsOfHead();
m_currentChangeset->setText(line);
// update heads list
QProcess process;
process.setWorkingDirectory(hgWrapper->getBaseDir());
QStringList args;
args << QLatin1String("heads");
args << QLatin1String("--template");
args << QLatin1String("{rev}\n{node|short}\n{branch}\n"
"{author}\n{desc|firstline}\n");
process.start(QLatin1String("hg"), args);
m_commitInfoWidget->clear();
const int FINAL = 5;
char buffer[FINAL][1024];
int count = 0;
while (process.waitForReadyRead()) {
while (process.readLine(buffer[count], sizeof(buffer[count])) > 0) {
if (count == FINAL - 1) {
QString rev = QTextCodec::codecForLocale()->toUnicode(buffer[0]).trimmed();
QString changeset = QTextCodec::codecForLocale()->toUnicode(buffer[1]).trimmed();
QString branch = QTextCodec::codecForLocale()->toUnicode(buffer[2]).trimmed();
QString author = QTextCodec::codecForLocale()->toUnicode(buffer[3]).trimmed();
QString log = QTextCodec::codecForLocale()->toUnicode(buffer[4]).trimmed();
QListWidgetItem *item = new QListWidgetItem;
item->setData(Qt::DisplayRole, changeset);
item->setData(Qt::UserRole + 1, rev);
item->setData(Qt::UserRole + 2, branch);
item->setData(Qt::UserRole + 3, author);
item->setData(Qt::UserRole + 4, log);
m_commitInfoWidget->addItem(item);
}
count = (count + 1)%FINAL;
}
}
}
void HgMergeDialog::done(int r)
{
if (r == KDialog::Accepted) {
HgWrapper *hgw = HgWrapper::instance();
QListWidgetItem *currentItem = m_commitInfoWidget->currentItem();
if (currentItem == 0) {
KMessageBox::error(this,
i18nc("@message", "No head selected for merge!"));
return;
}
QString changeset = m_commitInfoWidget->selectedChangeset();
QStringList args;
args << QLatin1String("-r");
args << changeset;
if (hgw->executeCommandTillFinished(QLatin1String("merge"), args)) {
KMessageBox::information(this, hgw->readAllStandardOutput());
KDialog::done(r);
}
else {
KMessageBox::error(this, hgw->readAllStandardError());
return;
}
}
else {
KDialog::done(r);
}
}
void HgMergeDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setMergeDialogHeight(this->height());
settings->setMergeDialogWidth(this->width());
settings->writeConfig();
}
#include "moc_mergedialog.cpp"

View file

@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGMERGE_H
#define HGMERGE_H
#include <QtCore/QString>
#include <kdialog.h>
class KComboBox;
class KPushButton;
#include <QLabel>
class HgCommitInfoWidget;
/**
* Implements dialog to perform merge operations
*/
class HgMergeDialog : public KDialog
{
Q_OBJECT
public:
HgMergeDialog(QWidget *parent = 0);
void done(int r);
private slots:
void saveGeometry();
private:
void updateInitialDialog();
private:
QLabel *m_currentChangeset;
HgCommitInfoWidget *m_commitInfoWidget;
};
#endif // HGMERGE_H

View file

@ -0,0 +1,98 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "pathselector.h"
#include "hgconfig.h"
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <kcombobox.h>
#include <klineedit.h>
#include <klocale.h>
HgPathSelector::HgPathSelector(QWidget *parent) :
QWidget(parent)
{
setupUI();
reload();
// connections
connect(m_selectPathAlias, SIGNAL(currentIndexChanged(int)),
this, SLOT(slotChangeEditUrl(int)));
connect(m_selectPathAlias, SIGNAL(highlighted(int)),
this, SLOT(slotChangeEditUrl(int)));
}
void HgPathSelector::setupUI()
{
QHBoxLayout *urlLayout = new QHBoxLayout;
m_selectPathAlias = new KComboBox;
m_urlEdit = new KLineEdit;
m_urlEdit->setReadOnly(true);
urlLayout->addWidget(m_selectPathAlias);
urlLayout->addWidget(m_urlEdit);
setLayout(urlLayout);
}
void HgPathSelector::reload()
{
HgConfig hgc(HgConfig::RepoConfig);
m_pathList = hgc.repoRemotePathList();
m_selectPathAlias->clear();
QMutableMapIterator<QString, QString> it(m_pathList);
while (it.hasNext()) {
it.next();
if (it.key() == QLatin1String("default")) {
m_selectPathAlias->insertItem(0, it.key());
}
else {
m_selectPathAlias->addItem(it.key());
}
}
m_selectPathAlias->addItem(i18nc("@label:combobox", "<edit>"));
slotChangeEditUrl(0);
}
void HgPathSelector::slotChangeEditUrl(int index)
{
if (index == m_selectPathAlias->count() - 1) { ///enter URL manually
m_urlEdit->setReadOnly(false);
m_urlEdit->clear();
m_urlEdit->setFocus();
}
else {
QString url = m_pathList[m_selectPathAlias->itemText(index)];
m_urlEdit->setText(url);
m_urlEdit->setReadOnly(true);
}
}
const QString HgPathSelector::remote() const
{
return (m_selectPathAlias->currentIndex() == m_selectPathAlias->count()-1)?m_urlEdit->text():m_selectPathAlias->currentText();
}
#include "moc_pathselector.cpp"

View file

@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGPATHSELECTOR_H
#define HGPATHSELECTOR_H
#include <QtGui/QWidget>
#include <QtCore/QMap>
class KComboBox;
class KLineEdit;
/**
* A simple widget which presents a ComboBox to select list of Path aliases
* stored in .hgrc file and show their URL. URL's can be entered manually
* as well.
*/
class HgPathSelector : public QWidget
{
Q_OBJECT
public:
HgPathSelector(QWidget *parent=0);
/**
* @return Return QString containing the selected/entered alias/URL
*/
const QString remote() const;
public slots:
void reload();
private:
void setupUI();
private slots:
void slotChangeEditUrl(int index);
private:
QMap<QString, QString> m_pathList;
KComboBox *m_selectPathAlias;
KLineEdit *m_urlEdit;
};
#endif /* HGPATHSELECTOR_H */

View file

@ -0,0 +1,172 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "pulldialog.h"
#include "hgwrapper.h"
#include "hgconfig.h"
#include "pathselector.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
#include <QtGui/QHeaderView>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QTableWidget>
#include <QtCore/QString>
#include <ktextedit.h>
#include <kcombobox.h>
#include <klocale.h>
#include <kurl.h>
#include <kmessagebox.h>
HgPullDialog::HgPullDialog(QWidget *parent):
HgSyncBaseDialog(HgSyncBaseDialog::PullDialog, parent)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Pull Repository"));
this->setButtons(KDialog::Ok | KDialog::Details | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Pull"));
this->setButtonText(KDialog::Details, i18nc("@action:button", "Options"));
setup();
}
void HgPullDialog::setOptions()
{
m_optUpdate = new QCheckBox(i18nc("@label:checkbox",
"Update to new branch head if changesets were pulled"));
m_optInsecure = new QCheckBox(i18nc("@label:checkbox",
"Do not verify server certificate"));
m_optForce = new QCheckBox(i18nc("@label:checkbox",
"Force Pull"));
m_optionGroup = new QGroupBox(i18nc("@label:group",
"Options"));
m_options << m_optForce;
m_options << m_optUpdate;
m_options << m_optInsecure;
}
void HgPullDialog::createChangesGroup()
{
m_changesGroup = new QGroupBox(i18nc("@label:group",
"Incoming Changes"));
QHBoxLayout *hbox = new QHBoxLayout;
m_changesList = new QTableWidget;
m_changesList->setColumnCount(4);
m_changesList->verticalHeader()->hide();
m_changesList->horizontalHeader()->hide();
m_changesList->setSelectionBehavior(QAbstractItemView::SelectRows);
m_changesList->setEditTriggers(QAbstractItemView::NoEditTriggers);
hbox->addWidget(m_changesList);
m_changesGroup->setLayout(hbox);
m_changesGroup->setVisible(false);
connect(this, SIGNAL(changeListAvailable()),
this, SLOT(slotUpdateChangesGeometry()));
}
void HgPullDialog::getHgChangesArguments(QStringList &args)
{
args << QLatin1String("incoming");
args << m_pathSelector->remote();
args << QLatin1String("--config");
args << QLatin1String("ui.verbose=False");
args << QLatin1String("--template");
args << QLatin1String("Commit: {rev}:{node|short} "
"{author} "
"{date|isodate} {desc|firstline}\n");
}
void HgPullDialog::parseUpdateChanges(const QString &input)
{
QStringList list = input.split(" ", QString::SkipEmptyParts);
QTableWidgetItem *author = new QTableWidgetItem;
QTableWidgetItem *changeset = new QTableWidgetItem;
QTableWidgetItem *date = new QTableWidgetItem;
QTableWidgetItem *summary = new QTableWidgetItem;
author->setForeground(Qt::darkRed);
changeset->setForeground(Qt::red);
date->setForeground(Qt::blue);
author->setText(list.takeFirst());
changeset->setText(list.takeFirst());
date->setText(list.takeFirst());
summary->setText(list.takeFirst());
int rowCount = m_changesList->rowCount();
m_changesList->insertRow(rowCount);
m_changesList->setItem(rowCount, 0, author);
m_changesList->setItem(rowCount, 1, changeset);
m_changesList->setItem(rowCount, 2, date);
m_changesList->setItem(rowCount, 3, summary);
}
void HgPullDialog::appendOptionArguments(QStringList &args)
{
if (m_optForce->isChecked()) {
args << QLatin1String("--force");
}
if (m_optUpdate->isChecked()) {
args << QLatin1String("--update");
}
if (m_optInsecure->isChecked()) {
args << QLatin1String("--insecure");
}
}
void HgPullDialog::slotUpdateChangesGeometry()
{
m_changesList->resizeColumnsToContents();
m_changesList->resizeRowsToContents();
m_changesList->horizontalHeader()->setStretchLastSection(true);
}
void HgPullDialog::readBigSize()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
m_bigSize = QSize(settings->pullDialogBigWidth(), settings->pushDialogBigHeight());
}
void HgPullDialog::writeBigSize()
{
kDebug() << "Saving geometry";
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setPullDialogBigWidth(m_bigSize.width());
settings->setPullDialogBigHeight(m_bigSize.height());
settings->writeConfig();
}
void HgPullDialog::noChangesMessage()
{
KMessageBox::information(this, i18nc("@message:info",
"No incoming changes!"));
}
#include "moc_pulldialog.cpp"

View file

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGPULLDILAOG_H
#define HGPULLDILAOG_H
#include "syncdialogbase.h"
#include <QCheckBox>
#include <QTableWidget>
class KTextEdit;
class KComboBox;
#include <QString>
/**
* Dialog to implement pull operation
*/
class HgPullDialog : public HgSyncBaseDialog
{
Q_OBJECT
public:
HgPullDialog(QWidget *parent = 0);
private:
void setOptions();
void parseUpdateChanges(const QString &input);
void appendOptionArguments(QStringList &args);
void createChangesGroup();
void getHgChangesArguments(QStringList &args);
void noChangesMessage();
private slots:
void slotUpdateChangesGeometry();
void readBigSize();
void writeBigSize();
private:
// Options
QCheckBox *m_optUpdate;
QCheckBox *m_optInsecure;
QCheckBox *m_optForce;
QGroupBox *m_optionGroup;
// incoming Changes
QTableWidget *m_changesList;
};
#endif // HGPULLDILAOG_H

View file

@ -0,0 +1,193 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "pushdialog.h"
#include "hgconfig.h"
#include "pathselector.h"
#include "fileviewhgpluginsettings.h"
#include <QtCore/QStringList>
#include <QtCore/QString>
#include <QtCore/QTextCodec>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QTableWidget>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <ktextedit.h>
#include <kcombobox.h>
#include <klocale.h>
#include <kurl.h>
#include <kmessagebox.h>
HgPushDialog::HgPushDialog(QWidget *parent):
HgSyncBaseDialog(HgSyncBaseDialog::PushDialog, parent)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Push Repository"));
this->setButtons(KDialog::Ok | KDialog::Details | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Push"));
this->setButtonText(KDialog::Details, i18nc("@action:button", "Options"));
setup();
}
void HgPushDialog::setOptions()
{
m_optAllowNewBranch = new QCheckBox(i18nc("@label:checkbox",
"Allow pushing a new branch"));
m_optInsecure = new QCheckBox(i18nc("@label:checkbox",
"Do not verify server certificate"));
m_optForce = new QCheckBox(i18nc("@label:checkbox",
"Force Push"));
m_optionGroup = new QGroupBox(i18nc("@label:group",
"Options"));
m_options << m_optForce;
m_options << m_optAllowNewBranch;
m_options << m_optInsecure;
}
void HgPushDialog::createChangesGroup()
{
m_changesGroup = new QGroupBox(i18nc("@label:group",
"Outgoing Changes"));
QHBoxLayout *hbox = new QHBoxLayout;
m_outChangesList = new QTableWidget;
m_changesetInfo = new KTextEdit;
m_outChangesList->setColumnCount(3);
m_outChangesList->verticalHeader()->hide();
m_outChangesList->horizontalHeader()->hide();
m_outChangesList->setSelectionBehavior(QAbstractItemView::SelectRows);
m_outChangesList->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_changesetInfo->setFontFamily(QLatin1String(KDE_DEFAULT_FIXED_FONT));
hbox->addWidget(m_outChangesList);
hbox->addWidget(m_changesetInfo);
m_changesGroup->setLayout(hbox);
m_changesGroup->setVisible(false);
connect(m_outChangesList, SIGNAL(itemSelectionChanged()),
this, SLOT(slotOutSelChanged()));
connect(this, SIGNAL(changeListAvailable()),
this, SLOT(slotUpdateChangesGeometry()));
}
void HgPushDialog::slotOutSelChanged()
{
if (m_hgw->isBusy()) {
return;
}
QString changeset = m_outChangesList->item(m_outChangesList->currentRow(), 0)->text().split(' ', QString::SkipEmptyParts).takeLast();
QStringList args;
args << QLatin1String("-r");
args << changeset;
args << QLatin1String("-v");
args << QLatin1String("-p");
QString output;
m_hgw->executeCommand(QLatin1String("log"), args, output);
m_changesetInfo->clear();
m_changesetInfo->setText(output);
}
void HgPushDialog::getHgChangesArguments(QStringList &args)
{
args << QLatin1String("outgoing");
args << m_pathSelector->remote();
args << QLatin1String("--config");
args << QLatin1String("ui.verbose=False");
args << QLatin1String("--template");
args << QLatin1String("Commit: {rev}:{node|short} "
"{date|isodate} {desc|firstline}\n");
}
void HgPushDialog::parseUpdateChanges(const QString &input)
{
QStringList list = input.split(" ", QString::SkipEmptyParts);
QTableWidgetItem *changeset = new QTableWidgetItem;
QTableWidgetItem *date = new QTableWidgetItem;
QTableWidgetItem *summary = new QTableWidgetItem;
changeset->setForeground(Qt::red);
date->setForeground(Qt::blue);
changeset->setText(list.takeFirst());
date->setText(list.takeFirst());
summary->setText(list.takeFirst());
int rowCount = m_outChangesList->rowCount();
m_outChangesList->insertRow(rowCount);
m_outChangesList->setItem(rowCount, 0, changeset);
m_outChangesList->setItem(rowCount, 1, date);
m_outChangesList->setItem(rowCount, 2, summary);
}
void HgPushDialog::appendOptionArguments(QStringList &args)
{
if (m_optForce->isChecked()) {
args << QLatin1String("--force");
}
if (m_optAllowNewBranch->isChecked()) {
args << QLatin1String("--new-branch");
}
if (m_optInsecure->isChecked()) {
args << QLatin1String("--insecure");
}
}
void HgPushDialog::slotUpdateChangesGeometry()
{
m_outChangesList->resizeColumnsToContents();
m_outChangesList->resizeRowsToContents();
m_outChangesList->horizontalHeader()->setStretchLastSection(true);
}
void HgPushDialog::readBigSize()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
m_bigSize = QSize(settings->pushDialogBigWidth(), settings->pushDialogBigHeight());
}
void HgPushDialog::writeBigSize()
{
kDebug() << "Saving geometry";
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setPushDialogBigWidth(m_bigSize.width());
settings->setPushDialogBigHeight(m_bigSize.height());
settings->writeConfig();
}
void HgPushDialog::noChangesMessage()
{
KMessageBox::information(this, i18nc("@message:info",
"No outgoing changes!"));
}
#include "moc_pushdialog.cpp"

View file

@ -0,0 +1,68 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGPUSHDILAOG_H
#define HGPUSHDILAOG_H
#include "hgwrapper.h"
#include "syncdialogbase.h"
#include <QCheckBox>
#include <QTableWidget>
class KTextEdit;
#include <QGroupBox>
/**
* Dialog to implement Push operation
*/
class HgPushDialog : public HgSyncBaseDialog
{
Q_OBJECT
public:
HgPushDialog(QWidget *parent = 0);
private:
void setOptions();
void createChangesGroup();
void parseUpdateChanges(const QString &input);
void appendOptionArguments(QStringList &args);
void getHgChangesArguments(QStringList &args);
void noChangesMessage();
private slots:
void slotOutSelChanged();
void slotUpdateChangesGeometry();
void readBigSize();
void writeBigSize();
private:
// Options
QCheckBox *m_optAllowNewBranch;
QCheckBox *m_optInsecure;
QCheckBox *m_optForce;
QGroupBox *m_optionGroup;
// outgoing Changes
QTableWidget *m_outChangesList;
KTextEdit *m_changesetInfo;
};
#endif // HGPUSHDILAOG_H

View file

@ -0,0 +1,94 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "renamedialog.h"
#include "hgwrapper.h"
#include <klocale.h>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QFrame>
#include <klineedit.h>
#include <kfileitem.h>
HgRenameDialog::HgRenameDialog(const KFileItem &source, QWidget *parent):
KDialog(parent, Qt::Dialog),
m_source(source.name()),
m_source_dir(source.url().directory())
{
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Rename"));
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Rename"));
QFrame *frame = new QFrame(this);
QGridLayout *mainLayout = new QGridLayout(frame);
QLabel *sourceLabel = new QLabel(i18nc("@label:label to source file",
"Source "), frame);
QLabel *sourceFileLabel = new QLabel("<b>" + m_source + "</b>");
mainLayout->addWidget(sourceLabel, 0, 0);
mainLayout->addWidget(sourceFileLabel, 0, 1);
QLabel *destinationLabel
= new QLabel(i18nc("@label:rename", "Rename to "), frame);
m_destinationFile = new KLineEdit(m_source, frame);
mainLayout->addWidget(destinationLabel, 1, 0);
mainLayout->addWidget(m_destinationFile, 1, 1);
frame->setLayout(mainLayout);
setMainWidget(frame);
m_destinationFile->setFocus();
m_destinationFile->selectAll();
connect(m_destinationFile, SIGNAL(textChanged(const QString &)),
this, SLOT(slotTextChanged(const QString &)));
}
void HgRenameDialog::slotTextChanged(const QString &text)
{
enableButtonOk(text.length() != 0);
}
void HgRenameDialog::done(int r)
{
if (r == KDialog::Accepted) {
HgWrapper *hgi = HgWrapper::instance();
hgi->renameFile(source(), destination());
}
KDialog::done(r);
}
QString HgRenameDialog::source() const
{
return m_source;
}
QString HgRenameDialog::destination() const
{
return m_destinationFile->text();
}
#include "moc_renamedialog.cpp"

View file

@ -0,0 +1,51 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGRENAMEDIALOG_H
#define HGRENAMEDIALOG_H
#include <kdialog.h>
#include <QtCore/QString>
class KLineEdit;
class KFileItem;
/**
* Dialog to rename files Mercurial way
*/
class HgRenameDialog : public KDialog
{
Q_OBJECT
public:
HgRenameDialog(const KFileItem &source, QWidget *parent = 0);
QString source() const;
QString destination() const;
void done(int r);
private slots:
void slotTextChanged(const QString &text);
private:
QString m_source;
QString m_source_dir;
KLineEdit *m_destinationFile;
};
#endif // HGRENAMEDIALOG_H

View file

@ -0,0 +1,169 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "servedialog.h"
#include "servewrapper.h"
#include "fileviewhgpluginsettings.h"
#include "hgwrapper.h"
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QSpinBox>
#include <QtGui/QTextEdit>
#include <QtGui/QLabel>
#include <klocale.h>
#include <kdebug.h>
#include <klineedit.h>
#include <kpushbutton.h>
#include <kmessagebox.h>
HgServeDialog::HgServeDialog(QWidget *parent) :
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Serve"));
this->setButtons(KDialog::None);
//
m_serverWrapper = HgServeWrapper::instance();
//
setupUI();
loadConfig();
// Load saved settings
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
this->setInitialSize(QSize(settings->serveDialogWidth(),
settings->serveDialogHeight()));
// connections
connect(this, SIGNAL(finished()), this, SLOT(saveGeometry()));
connect(m_startButton, SIGNAL(clicked()), this, SLOT(slotStart()));
connect(m_stopButton, SIGNAL(clicked()), this, SLOT(slotStop()));
connect(m_serverWrapper, SIGNAL(finished()),
this, SLOT(slotUpdateButtons()));
connect(m_serverWrapper, SIGNAL(started()),
this, SLOT(slotUpdateButtons()));
connect(m_serverWrapper, SIGNAL(error()),
this, SLOT(slotUpdateButtons()));
connect(m_serverWrapper, SIGNAL(error()),
this, SLOT(slotServerError()));
connect(m_serverWrapper,
SIGNAL(readyReadLine(const QString&, const QString&)),
this,
SLOT(appendServerOutput(const QString&, const QString&)));
}
void HgServeDialog::setupUI()
{
m_portNumber = new QSpinBox;
m_portNumber->setMinimum(0);
m_portNumber->setMaximum(65535);
m_portNumber->setValue(8000);
m_startButton = new KPushButton(i18nc("@label:button", "Start Server"));
m_stopButton = new KPushButton(i18nc("@label:button", "Stop Server"));
m_logEdit = new QTextEdit;
m_repoPathLabel = new QLabel;
m_logEdit->setReadOnly(true);
m_logEdit->setFontFamily(QLatin1String(KDE_DEFAULT_FIXED_FONT));
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonLayout->addWidget(m_startButton);
buttonLayout->addWidget(m_stopButton);
buttonLayout->addStretch();
QHBoxLayout *portLayout = new QHBoxLayout;
portLayout->addWidget(new QLabel(i18nc("@label", "Port")));
portLayout->addWidget(m_portNumber);
portLayout->addStretch();
QHBoxLayout *midLayout = new QHBoxLayout;
midLayout->addWidget(m_logEdit);
midLayout->addLayout(buttonLayout);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_repoPathLabel);
layout->addLayout(portLayout);
layout->addLayout(midLayout);
QWidget *widget = new QWidget;
widget->setLayout(layout);
setMainWidget(widget);
}
void HgServeDialog::loadConfig()
{
HgWrapper *hgw = HgWrapper::instance();
m_repoPathLabel->setText("<b>" + hgw->getBaseDir() + "</b>");
slotUpdateButtons();
}
void HgServeDialog::slotUpdateButtons()
{
if (m_serverWrapper->running(HgWrapper::instance()->getBaseDir())) {
m_startButton->setEnabled(false);
m_stopButton->setEnabled(true);
m_portNumber->setEnabled(false);
}
else {
m_startButton->setEnabled(true);
m_stopButton->setEnabled(false);
m_portNumber->setEnabled(true);
m_serverWrapper->cleanUnused();
}
}
void HgServeDialog::slotStart()
{
m_serverWrapper->startServer(HgWrapper::instance()->getBaseDir(),
m_portNumber->value());
}
void HgServeDialog::slotStop()
{
m_serverWrapper->stopServer(HgWrapper::instance()->getBaseDir());
}
void HgServeDialog::slotServerError()
{
m_serverWrapper->cleanUnused();
}
void HgServeDialog::appendServerOutput(const QString &repoLocation, const QString &line)
{
if (HgWrapper::instance()->getBaseDir() == repoLocation) {
m_logEdit->append(line);
}
}
void HgServeDialog::saveGeometry()
{
FileViewHgPluginSettings *settings = FileViewHgPluginSettings::self();
settings->setServeDialogHeight(this->height());
settings->setServeDialogWidth(this->width());
settings->writeConfig();
}
#include "moc_servedialog.cpp"

View file

@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HG_SERVE_DIALOG
#define HG_SERVE_DIALOG
#include <kdialog.h>
#include <QSpinBox>
class KPushButton;
#include <QTextEdit>
#include <QLabel>
class HgServeWrapper;
/**
* Implements dialog to Start and Stop Mercurial web server.
* Several server instances can be handled.
*/
class HgServeDialog : public KDialog
{
Q_OBJECT
public:
HgServeDialog(QWidget *parent = 0);
void setupUI();
void loadConfig();
public slots:
void slotStart();
void slotStop();
private slots:
void slotUpdateButtons();
void slotServerError();
void saveGeometry();
/**
* Append stdout and stderr to m_logEdit
*/
void appendServerOutput(const QString &repoLocation, const QString &line);
private:
QSpinBox *m_portNumber;
KPushButton *m_startButton;
KPushButton *m_stopButton;
QTextEdit *m_logEdit;
QLabel *m_repoPathLabel;
HgServeWrapper *m_serverWrapper;
};
#endif /* HG_SERVE_DIALOG */

View file

@ -0,0 +1,150 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "servewrapper.h"
#include "hgwrapper.h"
#include <QtCore/QTextCodec>
#include <klocale.h>
#include <kdebug.h>
HgServeWrapper *HgServeWrapper::m_instance = 0;
HgServeWrapper::HgServeWrapper(QObject *parent) :
QObject(parent)
{
}
HgServeWrapper::~HgServeWrapper()
{
QMutableHashIterator<QString, ServerProcessType*> it(m_serverList);
while (it.hasNext()) {
it.next();
///terminate server if not terminated already
if (it.value()->process.state() != QProcess::NotRunning) {
it.value()->process.terminate();
}
it.value()->deleteLater();
it.remove();
}
}
HgServeWrapper *HgServeWrapper::instance()
{
if (m_instance == 0) {
m_instance = new HgServeWrapper;
}
return m_instance;
}
void HgServeWrapper::startServer(const QString &repoLocation, int portNumber)
{
ServerProcessType *server = m_serverList.value(repoLocation, 0);
if (server != 0) {
m_serverList.remove(repoLocation);
server->deleteLater();
}
server = new ServerProcessType;
m_serverList.insert(repoLocation, server);
server->port = portNumber;
server->process.setWorkingDirectory(HgWrapper::instance()->getBaseDir());
connect(&server->process, SIGNAL(started()),
this, SIGNAL(started()));
connect(&server->process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotFinished(int, QProcess::ExitStatus)));
connect(server, SIGNAL(readyReadLine(const QString&, const QString&)),
this, SIGNAL(readyReadLine(const QString&, const QString&)));
QStringList args;
args << QLatin1String("-oL");
args << QLatin1String("hg");
args << QLatin1String("serve");
args << QLatin1String("--port");
args << QString::number(portNumber);
server->process.start(QLatin1String("stdbuf"), args);
emit readyReadLine(repoLocation,
i18n("## Starting Server ##"));
emit readyReadLine(repoLocation,
QString("% hg serve --port %1").arg(portNumber));
}
void HgServeWrapper::stopServer(const QString &repoLocation)
{
ServerProcessType *server = m_serverList.value(repoLocation, 0);
if (server == 0) {
return;
}
server->process.terminate();
}
bool HgServeWrapper::running(const QString &repoLocation)
{
ServerProcessType *server = m_serverList.value(repoLocation, 0);
if (server == 0) {
return false;
}
return ( server->process.state() == QProcess::Running ||
server->process.state() == QProcess::Starting);
}
void HgServeWrapper::slotFinished(int exitCode, QProcess::ExitStatus status)
{
if (exitCode == 0 && status == QProcess::NormalExit) {
emit finished();
}
else {
emit error();
}
}
QString HgServeWrapper::errorMessage(const QString &repoLocation)
{
ServerProcessType *server = m_serverList.value(repoLocation, 0);
if (server == 0) {
return QString();
}
return QTextCodec::codecForLocale()->toUnicode(server->process.readAllStandardError());
}
bool HgServeWrapper::normalExit(const QString &repoLocation)
{
ServerProcessType *server = m_serverList.value(repoLocation, 0);
if (server == 0) {
return true;
}
return (server->process.exitStatus() == QProcess::NormalExit &&
server->process.exitCode() == 0);
}
void HgServeWrapper::cleanUnused()
{
QMutableHashIterator<QString, ServerProcessType*> it(m_serverList);
while (it.hasNext()) {
it.next();
if (it.value()->process.state() == QProcess::NotRunning) {
it.value()->deleteLater();
it.remove();
}
}
}
#include "moc_servewrapper.cpp"

View file

@ -0,0 +1,170 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HG_SERVE_WRAPPER_H
#define HG_SERVE_WRAPPER_H
#include <QtCore/QHash>
#include <QtCore/QProcess>
#include <QtCore/QTextCodec>
#include <QtCore/QString>
#include <klocale.h>
class ServerProcessType;
/**
* Wrapper to manage web server instaces of mercurial repository. More than one
* server can be handled.
*
* This wrapper should be singleton hence only one instance should be created
* and used. Hence, never create an object statically or use 'new' operator.
* Use instance() method to get(create) an instance.
*/
class HgServeWrapper : public QObject
{
Q_OBJECT
public:
HgServeWrapper(QObject *parent=0);
~HgServeWrapper();
/**
* Returns pointer to singleton instance of the wrapper. An instance is
* created if none exists.
*
* @return Pointer to the instance
*/
static HgServeWrapper *instance();
/**
* Starts a new instance of server.
*
* @param repoLocation Path to repository which is to be hosted on server
* @param portNumber Port to create server on.
*
*/
void startServer(const QString &repoLocation, int portNumber);
/**
* Stops a server.
*
* @param repoLocation Path to repository whose server instance in this
* has to be stopped.
*/
void stopServer(const QString &repoLocation);
/**
* Checks whether a web server for given repository is running under this
* wrapper.
*
* @param repoLocation Path to repository
* @return true if runnning/started else false
*/
bool running(const QString &repoLocation);
/**
* Cleans all resources in this wrapper used by non-running servers
*/
void cleanUnused();
/**
* If terminated, get error message of that server instaces
*/
QString errorMessage(const QString &repoLocation);
/**
* Check if the just stopped server for given repository was
* exited successfully.
*
* @param repoLocation Path to repository
* @return true if exitCode == 0 and exitStatus == Normal, otherwise false
*/
bool normalExit(const QString &repoLocation);
signals:
// These signals are emitted for every ServerProcessType in list. Its upto
// the owner of this wrapper to decide which server was updated. If any of
// these signals are emitted cleanUnused() is called and every initiater
// of server should check status and act according.
void finished();
void error();
void started();
void readyReadLine(const QString &repoLocation, const QString &line);
private:
private slots:
void slotFinished(int exitCode, QProcess::ExitStatus status);
private:
QHash<QString, ServerProcessType*> m_serverList;
static HgServeWrapper *m_instance;
};
//FIXME: Had to change struct to class and make it unnested.
// Hide member variables.
/**
* Represents a Mercurial Server instace.
*/
class ServerProcessType : public QObject {
Q_OBJECT
public:
QProcess process;
int port;
ServerProcessType()
{
connect(&process, SIGNAL(readyReadStandardOutput()),
this, SLOT(slotAppendOutput()));
connect(&process, SIGNAL(readyReadStandardError()),
this, SLOT(slotAppendRemainingOutput()));
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotFinished()));
}
signals:
void readyReadLine(const QString &repoLocation, const QString &line);
private slots:
void slotAppendOutput()
{
if (process.canReadLine()) {
emit readyReadLine(process.workingDirectory(),
QTextCodec::codecForLocale()->toUnicode(process.readAllStandardOutput()).trimmed());
}
}
void slotAppendRemainingOutput()
{
emit readyReadLine(process.workingDirectory(),
QTextCodec::codecForLocale()->toUnicode(process.readAllStandardError()).trimmed());
}
void slotFinished()
{
emit readyReadLine(process.workingDirectory(),
i18n("## Server Stopped! ##\n"));
}
};
#endif /* HG_SERVE_WRAPPER_H */

View file

@ -0,0 +1,177 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "statuslist.h"
#include "hgwrapper.h"
#include <QtCore/QHash>
#include <QtCore/QTextCodec>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QTableWidget>
#include <klineedit.h>
#include <klocale.h>
#include <kurl.h>
#include <kdebug.h>
HgStatusList::HgStatusList(QWidget *parent):
QGroupBox(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
//m_filter = new KLineEdit(this);
m_statusTable = new QTableWidget(this);
m_statusTable->setColumnCount(3);
QStringList headers;
headers << "*" << "S" << i18n("Filename");
m_statusTable->setHorizontalHeaderLabels(headers);
m_statusTable->verticalHeader()->hide();
m_statusTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_statusTable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_statusTable->setSelectionMode(QAbstractItemView::SingleSelection);
//mainLayout->addWidget(m_filter);
mainLayout->addWidget(m_statusTable);
setTitle(i18nc("@title:group", "File Status"));
setLayout(mainLayout);
reloadStatusTable();
connect(m_statusTable,
SIGNAL(currentItemChanged(QTableWidgetItem*, QTableWidgetItem*)),
this, SLOT(currentItemChangedSlot()));
}
void HgStatusList::currentItemChangedSlot()
{
emit itemSelectionChanged(
m_statusTable->item(m_statusTable->currentRow(), 1)->text()[0].toLatin1(),
m_statusTable->item(m_statusTable->currentRow(), 2)->text());
}
void HgStatusList::reloadStatusTable()
{
m_statusTable->clearContents();
m_statusTable->resizeRowsToContents();
m_statusTable->resizeColumnsToContents();
m_statusTable->horizontalHeader()->setStretchLastSection(true);
HgWrapper *hgWrapper = HgWrapper::instance();
QHash<QString, KVersionControlPlugin::ItemVersion> hgVsState;
hgWrapper->getItemVersions(hgVsState);
QMutableHashIterator<QString, KVersionControlPlugin::ItemVersion> it(hgVsState);
int rowCount = 0;
while (it.hasNext()) {
it.next();
KVersionControlPlugin::ItemVersion currentStatus = it.value();
// Get path relative to root directory of repository
// FIXME: preferred method, but not working :| bad hack below
// QString currentFile
// = KUrl::relativeUrl(hgWrapper->getBaseDir(), it.key());
QString currentFile = it.key().mid(hgWrapper->getBaseDir().length()+1);
QString currentStatusString; //one character status indicator
// Temporarily ignoring
// TODO: Ask to add file if this is checked by user
if (currentStatus == KVersionControlPlugin::UnversionedVersion ||
currentStatus == KVersionControlPlugin::IgnoredVersion) {
continue;
}
QTableWidgetItem *check = new QTableWidgetItem;
QTableWidgetItem *status = new QTableWidgetItem;
QTableWidgetItem *fileName = new QTableWidgetItem;
switch (currentStatus) {
case KVersionControlPlugin::AddedVersion:
status->setForeground(Qt::darkCyan);
fileName->setForeground(Qt::darkCyan);
check->setCheckState(Qt::Checked);
currentStatusString = QLatin1String("A");
break;
case KVersionControlPlugin::LocallyModifiedVersion:
status->setForeground(Qt::blue);
fileName->setForeground(Qt::blue);
check->setCheckState(Qt::Checked);
currentStatusString = QLatin1String("M");
break;
case KVersionControlPlugin::RemovedVersion:
status->setForeground(Qt::red);
fileName->setForeground(Qt::red);
check->setCheckState(Qt::Checked);
currentStatusString = QLatin1String("R");
break;
case KVersionControlPlugin::UnversionedVersion:
status->setForeground(Qt::darkMagenta);
fileName->setForeground(Qt::darkMagenta);
currentStatusString = QLatin1String("?");
break;
case KVersionControlPlugin::IgnoredVersion:
status->setForeground(Qt::black);
fileName->setForeground(Qt::black);
currentStatusString = QLatin1String("I");
break;
case KVersionControlPlugin::MissingVersion:
status->setForeground(Qt::black);
fileName->setForeground(Qt::black);
currentStatusString = QLatin1String("!");
break;
default:
break;
}
status->setText(QString(currentStatusString));
fileName->setText(currentFile);
m_statusTable->insertRow(rowCount);
check->setCheckState(Qt::Checked); //Change. except untracked, ignored
m_statusTable->setItem(rowCount, 0, check);
m_statusTable->setItem(rowCount, 1, status);
m_statusTable->setItem(rowCount, 2, fileName);
++rowCount;
}
}
bool HgStatusList::getSelectionForCommit(QStringList &files)
{
int nChecked = 0;
int nRowCount = m_statusTable->rowCount();
for (int row = 0; row < nRowCount; row++) {
QTableWidgetItem *item = m_statusTable->item(row, 0);
if (item->checkState() == Qt::Checked) {
nChecked++;
files << m_statusTable->item(row, 2)->text();
}
}
// if all files are selected, clear the list
if (nChecked == nRowCount) {
files.clear();
}
// at least one file is checked
if (nChecked > 0) {
return true;
}
//nothing is selected
return false;
}
#include "moc_statuslist.cpp"

View file

@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef STATUSLIST_H
#define STATUSLIST_H
#include <QtGui/QGroupBox>
#include <QtCore/QString>
class KLineEdit;
#include <QTableWidget>
/**
* Shows a list of files and their corresponding version states in a table.
* Used in commit dialog.
*/
class HgStatusList : public QGroupBox
{
Q_OBJECT
public:
HgStatusList(QWidget *parent = 0);
/**
* Appends the list of selected files whose changes should be
* committed. If all files are selected, nothing is appended and true
* is returned. If no files are selected, false is returned.
*
* @param files Append all the selected files to this. If all files are
* selected, nothing is appended
* @return If at least one file is selected, true is returned; otherwise
* false.
*/
bool getSelectionForCommit(QStringList &files);
private slots:
void reloadStatusTable();
private slots:
void currentItemChangedSlot();
signals:
void itemSelectionChanged(const char status, const QString &fileName);
private:
QString m_hgBaseDir;
QTableWidget *m_statusTable;
//KLineEdit *m_filter;
};
#endif // STATUSLIST_H

View file

@ -0,0 +1,316 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "syncdialogbase.h"
#include "hgconfig.h"
#include "pathselector.h"
#include "fileviewhgpluginsettings.h"
#include <QtGui/QApplication>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QProgressBar>
#include <klineedit.h>
#include <ktextedit.h>
#include <kcombobox.h>
#include <kpushbutton.h>
#include <klocale.h>
#include <kurl.h>
#include <kmessagebox.h>
HgSyncBaseDialog::HgSyncBaseDialog(DialogType dialogType, QWidget *parent):
KDialog(parent, Qt::Dialog),
m_haveChanges(false),
m_terminated(false),
m_dialogType(dialogType)
{
m_hgw = HgWrapper::instance();
}
void HgSyncBaseDialog::setup()
{
createChangesGroup();
readBigSize();
setupUI();
connect(m_changesButton, SIGNAL(clicked()),
this, SLOT(slotGetChanges()));
connect(&m_process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(slotUpdateBusy(QProcess::ProcessState)));
connect(&m_main_process, SIGNAL(stateChanged(QProcess::ProcessState)),
this, SLOT(slotUpdateBusy(QProcess::ProcessState)));
connect(&m_main_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotOperationComplete(int, QProcess::ExitStatus)));
connect(&m_main_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotOperationError()));
connect(&m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(slotChangesProcessError()));
connect(&m_process, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(slotChangesProcessComplete(int, QProcess::ExitStatus)));
connect(this, SIGNAL(finished()), this, SLOT(slotWriteBigSize()));
}
void HgSyncBaseDialog::createOptionGroup()
{
setOptions();
QVBoxLayout *layout = new QVBoxLayout;
foreach (QCheckBox *cb, m_options) {
layout->addWidget(cb);
}
m_optionGroup = new QGroupBox;
m_optionGroup->setLayout(layout);
setDetailsWidget(m_optionGroup);
}
void HgSyncBaseDialog::setupUI()
{
// top url bar
m_pathSelector = new HgPathSelector;
// changes button
//FIXME not very good idea. Bad HACK
if (m_dialogType == PullDialog) {
m_changesButton = new KPushButton(i18nc("@label:button",
"Show Incoming Changes"));
}
else {
m_changesButton = new KPushButton(i18nc("@label:button",
"Show Outgoing Changes"));
}
m_changesButton->setSizePolicy(QSizePolicy::Fixed,
QSizePolicy::Fixed);
m_changesButton->setCheckable(true);
// dialog's main widget
QWidget *widget = new QWidget;
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_pathSelector);
// changes
m_changesGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainLayout->addWidget(m_changesGroup);
// bottom bar
QHBoxLayout *bottomLayout = new QHBoxLayout;
m_statusProg = new QProgressBar;
m_statusProg->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
bottomLayout->addWidget(m_changesButton, Qt::AlignLeft);
bottomLayout->addStretch();
bottomLayout->addWidget(m_statusProg);
//
mainLayout->addLayout(bottomLayout);
widget->setLayout(mainLayout);
createOptionGroup();
setMainWidget(widget);
}
void HgSyncBaseDialog::slotGetChanges()
{
if (m_haveChanges) {
m_changesGroup->setVisible(!m_changesGroup->isVisible());
m_changesButton->setChecked(m_changesGroup->isVisible());
if (m_changesGroup->isVisible()) {
loadBigSize();
}
else {
loadSmallSize();
}
return;
}
if (m_process.state() == QProcess::Running) {
return;
}
QStringList args;
getHgChangesArguments(args);
m_process.setWorkingDirectory(m_hgw->getBaseDir());
m_process.start(QLatin1String("hg"), args);
}
void HgSyncBaseDialog::slotChangesProcessComplete(int exitCode, QProcess::ExitStatus status)
{
if (exitCode != 0 || status != QProcess::NormalExit) {
QString message = QTextCodec::codecForLocale()->toUnicode(m_process.readAllStandardError());
if (message.isEmpty()) {
message = i18nc("@message", "No changes found!");
}
KMessageBox::error(this, message);
return;
}
char buffer[512];
/**
* unwantedRead boolean to ensure that unwanted information messages
* by mercurial are filtered out.
* eg. Comparing with /path/to/repository
* Searching for changes
*/
bool unwantedRead = false;
/**
* hasChanges boolean checks whether there are any changes to be sent
* or received and invoke noChangesMessage() if its false
*/
bool hasChanges = false;
while (m_process.readLine(buffer, sizeof(buffer)) > 0) {
QString line(QTextCodec::codecForLocale()->toUnicode(buffer));
if (unwantedRead ) {
line.remove(QLatin1String("Commit: "));
parseUpdateChanges(line.trimmed());
hasChanges = true;;
}
else if (line.startsWith(QLatin1String("Commit: "))) {
unwantedRead = true;
line.remove(QLatin1String("Commit: "));
parseUpdateChanges(line.trimmed());
hasChanges = true;
}
}
if (!hasChanges) {
noChangesMessage();
}
m_changesGroup->setVisible(true);
m_changesButton->setChecked(true);
loadBigSize();
m_haveChanges = true;
emit changeListAvailable();
}
void HgSyncBaseDialog::slotChangesProcessError()
{
kDebug() << "Cant get changes";
KMessageBox::error(this, i18n("Error!"));
}
void HgSyncBaseDialog::loadSmallSize()
{
m_bigSize = size();
resize(m_smallSize);
}
void HgSyncBaseDialog::loadBigSize()
{
m_smallSize = size();
resize(m_bigSize);
}
void HgSyncBaseDialog::slotWriteBigSize()
{
if (m_changesGroup->isVisible()) {
m_bigSize = size();
}
writeBigSize();
}
void HgSyncBaseDialog::done(int r)
{
if (r == KDialog::Accepted) {
if (m_main_process.state() == QProcess::Running ||
m_main_process.state() == QProcess::Starting) {
kDebug() << "HgWrapper already busy";
return;
}
QStringList args;
QString command = (m_dialogType==PullDialog)?"pull":"push";
args << command;
args << m_pathSelector->remote();
appendOptionArguments(args);
m_terminated = false;
m_main_process.setWorkingDirectory(m_hgw->getBaseDir());
m_main_process.start(QLatin1String("hg"), args);
}
else {
if (m_process.state() == QProcess::Running ||
m_process.state() == QProcess::Starting ||
m_main_process.state() == QProcess::Running ||
m_main_process.state() == QProcess::Starting)
{
if (m_process.state() == QProcess::Running ||
m_process.state() == QProcess::Starting) {
m_process.terminate();
}
if (m_main_process.state() == QProcess::Running ||
m_main_process.state() == QProcess::Starting) {
kDebug() << "terminating pull/push process";
m_terminated = true;
m_main_process.terminate();
}
}
else {
KDialog::done(r);
}
}
}
void HgSyncBaseDialog::slotOperationComplete(int exitCode, QProcess::ExitStatus status)
{
if (exitCode == 0 && status == QProcess::NormalExit) {
KDialog::done(KDialog::Accepted);
}
else {
if (!m_terminated) {
KMessageBox::error(this, i18n("Error!"));
}
}
}
void HgSyncBaseDialog::slotOperationError()
{
KMessageBox::error(this, i18n("Error!"));
}
void HgSyncBaseDialog::slotUpdateBusy(QProcess::ProcessState state)
{
if (state == QProcess::Running || state == QProcess::Starting) {
m_statusProg->setRange(0, 0);
m_changesButton->setEnabled(false);
m_changesButton->setChecked(true);
this->enableButtonOk(false);
}
else {
m_statusProg->setRange(0, 100);
m_changesButton->setEnabled(true);
this->enableButtonOk(true);
}
m_statusProg->repaint();
QApplication::processEvents();
}
#include "moc_syncdialogbase.cpp"

View file

@ -0,0 +1,110 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGSYNCBASEDIALOG_H
#define HGSYNCBASEDIALOG_H
#include "hgwrapper.h"
#include <QtCore/QString>
#include <QtCore/QProcess>
#include <QtCore/QSize>
#include <QtCore/QMap>
#include <kdialog.h>
#include <QLabel>
#include <QCheckBox>
#include <QGroupBox>
#include <QProgressBar>
class KLineEdit;
class KTextEdit;
class KComboBox;
class KPushButton;
class HgPathSelector;
//TODO: Save/Load dialog geometry
//TODO: HTTPS login
//
/**
* Abstract class which implements common features of Push and Pull dialog.
* Inherited by HgPushDialog and HgPullDialog.
*/
class HgSyncBaseDialog : public KDialog
{
Q_OBJECT
public:
enum DialogType {PushDialog, PullDialog};
HgSyncBaseDialog(DialogType dialogType, QWidget *parent = 0);
signals:
void changeListAvailable();
protected:
void done(int r);
void setupUI();
void createOptionGroup();
void setup();
void loadSmallSize();
void loadBigSize();
virtual void setOptions() = 0;
virtual void createChangesGroup() = 0;
virtual void parseUpdateChanges(const QString &input) = 0;
virtual void appendOptionArguments(QStringList &args) = 0;
virtual void getHgChangesArguments(QStringList &args) = 0;
virtual void noChangesMessage() = 0;
protected slots:
void slotGetChanges();
void slotChangesProcessComplete(int exitCode, QProcess::ExitStatus status);
void slotChangesProcessError();
void slotOperationComplete(int exitCode, QProcess::ExitStatus status);
void slotOperationError();
void slotUpdateBusy(QProcess::ProcessState state);
void slotWriteBigSize();
virtual void writeBigSize() = 0;
virtual void readBigSize() = 0;
protected:
HgPathSelector *m_pathSelector;
QProgressBar *m_statusProg;
bool m_haveChanges;
bool m_terminated;
HgWrapper *m_hgw;
DialogType m_dialogType;
// Options
QList<QCheckBox*> m_options;
QGroupBox *m_optionGroup;
// geometry
QSize m_smallSize;
QSize m_bigSize;
// changes
KPushButton *m_changesButton;
QGroupBox *m_changesGroup;
QProcess m_process;
QProcess m_main_process; //should I use another process?
};
#endif // HGSYNCBASEDIALOG_H

View file

@ -0,0 +1,161 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "tagdialog.h"
#include "hgwrapper.h"
#include <QtGui/QFrame>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <kpushbutton.h>
#include <kcombobox.h>
#include <klocale.h>
#include <klineedit.h>
#include <kdebug.h>
#include <kmessagebox.h>
HgTagDialog::HgTagDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Tag"));
this->setButtons(KDialog::None);
// UI
QFrame *frame = new QFrame;
QVBoxLayout *vbox = new QVBoxLayout;
m_tagComboBox = new KComboBox;
m_tagComboBox->setEditable(true);
vbox->addWidget(m_tagComboBox);
QHBoxLayout *buttonLayout = new QHBoxLayout;
m_createTag = new KPushButton(i18n("Create New Tag"));
m_removeTag = new KPushButton(i18n("Remove Tag"));
m_updateTag = new KPushButton(i18n("Switch Tag"));
buttonLayout->addWidget(m_createTag);
buttonLayout->addWidget(m_removeTag);
buttonLayout->addWidget(m_updateTag);
vbox->addLayout(buttonLayout);
m_createTag->setEnabled(false);
m_updateTag->setEnabled(false);
m_removeTag->setEnabled(false);
frame->setLayout(vbox);
updateInitialDialog();
slotUpdateDialog(QString());
setMainWidget(frame);
slotUpdateDialog(m_tagComboBox->currentText());
QLineEdit *m_lineEdit = m_tagComboBox->lineEdit();
// connections
connect(m_createTag, SIGNAL(clicked()),
this, SLOT(slotCreateTag()));
connect(m_removeTag, SIGNAL(clicked()),
this, SLOT(slotRemoveTag()));
connect(m_updateTag, SIGNAL(clicked()),
this, SLOT(slotSwitch()));
connect(m_tagComboBox, SIGNAL(editTextChanged(const QString&)),
this, SLOT(slotUpdateDialog(const QString&)));
connect(m_lineEdit, SIGNAL(textChanged(const QString&)),
this, SLOT(slotUpdateDialog(const QString&)));
}
void HgTagDialog::updateInitialDialog()
{
HgWrapper *hgWrapper = HgWrapper::instance();
// update combo box
m_tagList = hgWrapper->getTags();
m_tagComboBox->addItems(m_tagList);
}
void HgTagDialog::slotUpdateDialog(const QString &text)
{
// update pushbuttons
if (text.length() == 0) {
m_createTag->setEnabled(false);
m_updateTag->setEnabled(false);
m_removeTag->setEnabled(false);
}
else if (m_tagList.contains(text)) {
m_createTag->setEnabled(false);
m_updateTag->setEnabled(true);
m_removeTag->setEnabled(true);
}
else {
m_createTag->setEnabled(true);
m_updateTag->setEnabled(false);
m_removeTag->setEnabled(false);
}
}
void HgTagDialog::slotSwitch()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString out;
QStringList args;
args << QLatin1String("-c");
args << m_tagComboBox->currentText();
if (hgWrapper->executeCommand(QLatin1String("update"), args, out)) {
//KMessageBox::information(this, i18n("Updated working directory!"));
done(KDialog::Ok);
}
else {
KMessageBox::error(this, i18n("Some error occurred"));
}
}
void HgTagDialog::slotRemoveTag()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString out;
QStringList args;
args << QLatin1String("--remove");
args << m_tagComboBox->currentText();
if (hgWrapper->executeCommand(QLatin1String("tag"), args, out)) {
//KMessageBox::information(this, i18n("Removed tag successfully!"));
done(KDialog::Ok);
}
else {
KMessageBox::error(this, i18n("Some error occurred"));
}
}
void HgTagDialog::slotCreateTag()
{
HgWrapper *hgWrapper = HgWrapper::instance();
QString out;
QStringList args;
args << m_tagComboBox->currentText();
if (hgWrapper->executeCommand(QLatin1String("tag"), args, out)) {
KMessageBox::information(this, i18n("Created tag successfully!"));
done(KDialog::Ok);
}
else {
KMessageBox::error(this, i18n("Some error occurred"));
}
}
#include "moc_tagdialog.cpp"

View file

@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef HGTAGDIALOG_H
#define HGTAGDIALOG_H
#include <QtCore/QString>
#include <kdialog.h>
class KComboBox;
class KPushButton;
/**
* Dialog to create/delete/list tags and update working directory to revision
* represented by a specific tag.
*/
class HgTagDialog : public KDialog
{
Q_OBJECT
public:
HgTagDialog(QWidget *parent = 0);
public slots:
void slotUpdateDialog(const QString &text);
void slotCreateTag();
void slotSwitch();
void slotRemoveTag();
private:
void updateInitialDialog();
private:
KComboBox *m_tagComboBox;
KPushButton *m_createTag;
KPushButton *m_updateTag;
KPushButton *m_removeTag;
QStringList m_tagList;
};
#endif // HGTAGDIALOG_H

View file

@ -0,0 +1,155 @@
/***************************************************************************
* Copyright (C) 2011 by Vishesh Yadav <vishesh3y@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "updatedialog.h"
#include "hgwrapper.h"
#include <QtGui/QLabel>
#include <QtGui/QGroupBox>
#include <QtGui/QFrame>
#include <QtGui/QHBoxLayout>
#include <QtGui/QVBoxLayout>
#include <QtGui/QCheckBox>
#include <kpushbutton.h>
#include <kcombobox.h>
#include <klocale.h>
#include <klistwidget.h>
#include <kmessagebox.h>
#include <kdebug.h>
HgUpdateDialog::HgUpdateDialog(QWidget *parent):
KDialog(parent, Qt::Dialog)
{
// dialog properties
this->setCaption(i18nc("@title:window",
"<application>Hg</application> Update"));
this->setButtons(KDialog::None);
this->setButtons(KDialog::Ok | KDialog::Cancel);
this->setDefaultButton(KDialog::Ok);
this->setButtonText(KDialog::Ok, i18nc("@action:button", "Update"));
// UI
QGroupBox *selectGroup = new QGroupBox(i18n("New working directory"));
QVBoxLayout *selectLayout = new QVBoxLayout;
m_selectType = new KComboBox;
m_selectFinal = new KComboBox;
m_selectType->addItem(i18n("Branch"));
m_selectType->addItem(i18n("Tag"));
m_selectType->addItem(i18n("Changeset/Revision"));
selectLayout->addWidget(m_selectType);
selectLayout->addWidget(m_selectFinal);
selectGroup->setLayout(selectLayout);
QGroupBox *infoGroup = new QGroupBox(i18n("Current Parent"));
QVBoxLayout *infoLayout = new QVBoxLayout;
m_currentInfo = new QLabel;
infoLayout->addWidget(m_currentInfo);
infoGroup->setLayout(infoLayout);
QGroupBox *optionGroup = new QGroupBox(i18n("Options"));
QVBoxLayout *optionLayout = new QVBoxLayout;
m_discardChanges = new QCheckBox("Discard uncommitted changes");
m_discardChanges->setCheckState(Qt::Unchecked);
optionLayout->addWidget(m_discardChanges);
optionGroup->setLayout(optionLayout);
QFrame *frame = new QFrame;
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(infoGroup);
mainLayout->addWidget(selectGroup);
mainLayout->addWidget(optionGroup);
frame->setLayout(mainLayout);
slotUpdateDialog(0);
setMainWidget(frame);
// connections
connect(m_selectType, SIGNAL(currentIndexChanged(int)), this,
SLOT(slotUpdateDialog(int)));
}
void HgUpdateDialog::slotUpdateDialog(int index)
{
HgWrapper *hgWrapper = HgWrapper::instance();
m_selectFinal->clear();
if (index == 0) {
m_updateTo = ToBranch;
m_selectFinal->setEditable(false);
m_selectFinal->addItems(hgWrapper->getBranches());
}
else if (index == 1) {
m_updateTo = ToTag;
m_selectFinal->setEditable(false);
m_selectFinal->addItems(hgWrapper->getTags());
}
else if (index == 2) {
m_updateTo = ToRevision;
m_selectFinal->setEditable(true);
}
m_selectFinal->setFocus();
/// get parents of current working directory
/// more precise informtaion using 'hg summary'
/// but no proper way to retrieve needed data
QString output;
QStringList args;
args << QLatin1String("--template");
args << QLatin1String("{rev}:{node|short} ({branch})\n");
hgWrapper->executeCommand(QLatin1String("parents"), args, output);
output.replace(QLatin1String("\n"), QLatin1String("<br/>"));
if (output.contains(QLatin1String("()"))) {
output.replace(QLatin1String("()"), QLatin1String("(default)"));
}
m_currentInfo->setText(output);
}
void HgUpdateDialog::done(int r)
{
if (r == KDialog::Accepted) {
QStringList args;
// Should we discard uncommitted changes
if (m_discardChanges->checkState() == Qt::Checked) {
args << "-C";
}
else {
args << "-c";
}
if (m_updateTo == ToRevision) {
args << "-r";
}
// update to
args << m_selectFinal->currentText();
// execute mercurial command
HgWrapper *hgw = HgWrapper::instance();
if (hgw->executeCommandTillFinished(QLatin1String("update"), args)) {
KDialog::done(r);
}
else {
KMessageBox::error(this, i18n("Some error occurred! "
"\nMaybe there are uncommitted changes."));
}
}
else {
KDialog::done(r);
}
}
#include "moc_updatedialog.cpp"

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